MCPcopy Create free account
hub / github.com/reactive-python/reactpy / _setup_common_routes

Function _setup_common_routes

src/py/reactpy/reactpy/backend/sanic.py:105–155  ·  view source on GitHub ↗
(
    api_blueprint: Blueprint,
    spa_blueprint: Blueprint,
    options: Options,
)

Source from the content-addressed store, hash-verified

103
104
105def _setup_common_routes(
106 api_blueprint: Blueprint,
107 spa_blueprint: Blueprint,
108 options: Options,
109) -> None:
110 cors_options = options.cors
111 if cors_options: # nocov
112 cors_params = cors_options if isinstance(cors_options, dict) else {}
113 CORS(api_blueprint, **cors_params)
114
115 index_html = read_client_index_html(options)
116
117 async def single_page_app_files(
118 request: request.Request[Any, Any],
119 _: str = "",
120 ) -> response.HTTPResponse:
121 return response.html(index_html)
122
123 if options.serve_index_route:
124 spa_blueprint.add_route(
125 single_page_app_files,
126 "/",
127 name="single_page_app_files_root",
128 )
129 spa_blueprint.add_route(
130 single_page_app_files,
131 "/<_:path>",
132 name="single_page_app_files_path",
133 )
134
135 async def asset_files(
136 request: request.Request[Any, Any],
137 path: str = "",
138 ) -> response.HTTPResponse:
139 path = urllib_parse.unquote(path)
140 return await response.file(safe_client_build_dir_path(f"assets/{path}"))
141
142 api_blueprint.add_route(asset_files, f"/{ASSETS_PATH.name}/<path:path>")
143
144 async def web_module_files(
145 request: request.Request[Any, Any],
146 path: str,
147 _: str = "", # this is not used
148 ) -> response.HTTPResponse:
149 path = urllib_parse.unquote(path)
150 return await response.file(
151 safe_web_modules_dir_path(path),
152 mime_type="text/javascript",
153 )
154
155 api_blueprint.add_route(web_module_files, f"/{MODULES_PATH.name}/<path:path>")
156
157
158def _setup_single_view_dispatcher_route(

Callers 1

configureFunction · 0.70

Calls 1

read_client_index_htmlFunction · 0.90

Tested by

no test coverage detected