docs_src/behind_a_proxy/tutorial004_py310.py
raw| 1 | from fastapi import FastAPI, Request |
| 2 | |
| 3 | app = FastAPI( |
| 4 | servers=[ |
| 5 | {"url": "https://stag.example.com", "description": "Staging environment"}, |
| 6 | {"url": "https://prod.example.com", "description": "Production environment"}, |
| 7 | ], |
| 8 | root_path="/api/v1", |
| 9 | root_path_in_servers=False, |
| 10 | ) |
| 11 | |
| 12 | |
| 13 | @app.get("/app") |
| 14 | def read_main(request: Request): |
| 15 | return {"message": "Hello World", "root_path": request.scope.get("root_path")} |