@@ -152,18 +152,22 @@ async def generic_exception_handler(request: Request, exc: Exception) -> JSONRes
152152 return JSONResponse ({"detail" : "Internal server error" }, status_code = 500 )
153153
154154
155- app .mount (" /static" , StaticFiles (directory = "static" ), name = "static" )
155+ app .mount (f" { config . api_prefix } /static" , StaticFiles (directory = "static" ), name = "static" )
156156
157157for tag , router in routers .items ():
158+ assert router .prefix == config .api_prefix , f"Prefix not set on router with tag `{ tag } `"
158159 app .include_router (router , tags = [tag ])
159160
160161if config .serve_frontend :
161- frontend_root = Path ("frontend-dist" ).resolve ()
162+ msg = "API_PREFIX env var must be set (e.g. `/api`) when serving the frontend"
163+ assert config .api_prefix .startswith ("/" ), msg
164+
165+ frontend_root = Path ("frontend-dist" )
162166 allowed_paths = list (glob .iglob ("frontend-dist/**/*" , recursive = True ))
163167
164168 @app .get ("/{full_path:path}" )
165169 async def frontend (full_path : str ) -> FileResponse :
166- path = ( frontend_root / Path (full_path )). resolve ( )
170+ path = frontend_root / Path (full_path )
167171
168172 # Checking `str(path) in allowed_paths` should be enough here but we check for more cases
169173 # to be sure and avoid AI tools raising false positives.
0 commit comments