Skip to content

Behind a Proxy

When running behind a proxy, set root_path so JustAPI knows the external path:

app = JustAPIApp(root_path="/api/v1")
location /api/ {
proxy_pass http://localhost:8000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}

Cloudflare automatically adds the right headers. JustAPI detects them:

app = JustAPIApp(root_path="/")
from starlette.middleware.trustedhost import TrustedHostMiddleware
app.add_middleware(
TrustedHostMiddleware,
allowed_hosts=["example.com", "*.example.com"],
)