mirror of
https://github.com/fastapi/fastapi.git
synced 2026-05-18 21:39:22 -04:00
✨ Auto-generate OpenAPI servers from root_path (#1596)
* root_path included in servers object instead of path prefix * ♻️ Refactor implementation of auto-including root_path in OpenAPI servers * 📝 Update docs and examples for Behind a Proxy, including servers * 📝 Update Extending OpenAPI as openapi_prefix is no longer needed * ✅ Add extra tests for root_path in servers and root_path_in_servers=False * 🍱 Update security docs images with relative token URL * 📝 Update security docs with relative token URL * 📝 Update example sources with relative token URLs * ✅ Update tests with relative tokens Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
15
docs_src/behind_a_proxy/tutorial004.py
Normal file
15
docs_src/behind_a_proxy/tutorial004.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from fastapi import FastAPI, Request
|
||||
|
||||
app = FastAPI(
|
||||
servers=[
|
||||
{"url": "https://stag.example.com", "description": "Staging environment"},
|
||||
{"url": "https://prod.example.com", "description": "Production environment"},
|
||||
],
|
||||
root_path="/api/v1",
|
||||
root_path_in_servers=False,
|
||||
)
|
||||
|
||||
|
||||
@app.get("/app")
|
||||
def read_main(request: Request):
|
||||
return {"message": "Hello World", "root_path": request.scope.get("root_path")}
|
||||
Reference in New Issue
Block a user