サンプル
Configure FastAPI behind a reverse proxy prefix with root_path and root_path_in_servers without route matching 404s or broken Swagger UI docs
sha256:fc03836e42df24fc9ebcc02153f8212390e8abec2d04d133be4cc5598abd71d4
PUBLISHED
L3_CONTRACT_PASS
MIT-0
ケース
- ゴール
- Configure FastAPI behind a reverse proxy prefix with root_path and root_path_in_servers without route matching 404s or broken Swagger UI docs HOW
- パッケージ
- fastapi 0.141.1 starlette 1.6.0 httpx2 2.10.0 pydantic 2.13.4
- 環境
- python
- 作成日
- 2026-08-16T06:22:44Z
コントラクト
- assert Starlette get_route_path strips root_path from ASGI scope path, dispatching /api/v1/items/42 to @app.get('/items/{item_id}')
- assert defining route decorators with root_path prefix as @app.get('/api/v1/trapped') fails matching and 404s on /api/v1/trapped
- assert a trailing slash on root_path='/api/v1/' prevents prefix stripping in get_route_path, returning 404 on proxied requests
- assert request.url_for automatically includes root_path without manual string concatenation
- assert static app.openapi() contains no servers, while the ASGI GET /openapi.json endpoint dynamically injects [{'url': '/api/v1'}]
- assert FastAPI(root_path_in_servers=False) suppresses OpenAPI servers injection
- assert Swagger UI /docs dynamically configures the JS bundle to fetch /api/v1/openapi.json
- assert mounting a sub-app at /v2 composes root_path to /api/v1/v2 for routing, url_for, and OpenAPI documentation
ファイル
- NOTES.md
- csx.json
- requirements.txt
- src/__init__.py
- src/app.py
- test/contract.py
検証済みアーティファクトをダウンロード (tar.gz) — 契約が実行された正確なバイト列
オリジンシーダー
検証レシート
- python 3.12 · CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · python@1 · 2026-08-16 · ed25519:d91480838ac982c9