Skip to content

gdamjan/fastapi-proxied

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI behind ALB, non-root url prefix

Research fastapi/uvicorn behaviour when proxied by AWS ALB, behind a non-root (/) url path - /api in these examples. ALB doesn't rewrite the url request, so when "mounting" a FastAPI application under a prefix (for ex. /api) the application gets the whole url path (for ex. /api/a/b/c).

Quickstart

uv sync
uv run pytest
FASTAPI_ROOT_PATH=/api/ uv run uvicorn demo:app

Expected response from all 3 variants:

$ curl http://127.0.0.1:8000/api/
{"message":"Hello World","root_path":"/api/"}

$ curl -s http://127.0.0.1:8000/api/openapi.json | jq '.servers[0].url'
"/api"

References

Additional tests

uv run uvicorn --root-path=/app/v1 --interface wsgi demo:wsgi_app
uv run uvicorn --root-path=/app/v1 demo:asgi_app
uv run uvicorn --root-path=/app/v1 demo:starlette

About

FastAPI behind ALB, non-root url prefix

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages