Skip to content

Reverse proxy and sub-apps

The ASGI root_path, set by the server behind a proxy (--root-path) or by app.mount(), is picked up automatically in every per-version doc URL:

parent = FastAPI()
parent.mount("/api", app)  # root_path="/api" is injected per request
# /api/v1_0/docs correctly points at /api/v1_0/openapi.json

For the proxy side (stripping the prefix, --root-path), see FastAPI's Behind a Proxy guide.

A mounted sub-application is a separate FastAPI() instance, so a RouterVersioner attached to it is entirely independent from one attached to the parent, or to another sub-application, with no prefix coordination needed. See examples/mounted_subapps_app.py.