@@ -29,8 +29,20 @@ def create_app(settings: Optional[Settings] = None) -> FastAPI:
2929
3030 app = FastAPI (
3131 openapi_url = None , # Disable OpenAPI schema endpoint, we want to serve upstream's schema
32+
33+ # Add catchall proxy handler
34+ proxy_handler = ReverseProxyHandler (upstream = str (settings .upstream_url ))
35+ app .add_api_route (
36+ "/{path:path}" ,
37+ proxy_handler .stream ,
38+ methods = ["GET" , "POST" , "PUT" , "PATCH" , "DELETE" ],
3239 )
3340
41+ if settings .healthz_prefix :
42+ healthz_handler = HealthzHandler (upstream_url = str (settings .upstream_url ))
43+ app .include_router (healthz_handler .router , prefix = "/healthz" )
44+
45+ # Add middleware in reverse order (last added = first to run)
3446 app .add_middleware (AddProcessTimeHeaderMiddleware )
3547
3648 if settings .openapi_spec_endpoint :
@@ -59,16 +71,4 @@ def create_app(settings: Optional[Settings] = None) -> FastAPI:
5971 oidc_config_url = settings .oidc_discovery_url ,
6072 )
6173
62- if settings .healthz_prefix :
63- healthz_handler = HealthzHandler (upstream_url = str (settings .upstream_url ))
64- app .include_router (healthz_handler .router , prefix = "/healthz" )
65-
66- # Catchall for any endpoint
67- proxy_handler = ReverseProxyHandler (upstream = str (settings .upstream_url ))
68- app .add_api_route (
69- "/{path:path}" ,
70- proxy_handler .stream ,
71- methods = ["GET" , "POST" , "PUT" , "PATCH" , "DELETE" ],
72- )
73-
7474 return app
0 commit comments