Python / Django
Configure Django, Flask, and FastAPI to work behind Hatch's reverse proxy.
Map your domain
hatch add api.test 8000 --https
Django
Django validates the Host header and CSRF origin. Add your Hatch domain to both:
# settings.py
ALLOWED_HOSTS = ['api.test', 'localhost', '127.0.0.1']
CSRF_TRUSTED_ORIGINS = ['https://api.test']
# Trust Hatch's proxy headers
USE_X_FORWARDED_HOST = True
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')Run the dev server on all interfaces:
python manage.py runserver 0.0.0.0:8000
Flask
Flask works out of the box — just bind to all interfaces:
# app.py app.run(host='0.0.0.0', port=8000) # Or with the CLI flask run --host 0.0.0.0 --port 8000
For proxy header support, use ProxyFix:
from werkzeug.middleware.proxy_fix import ProxyFix app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1, x_proto=1, x_host=1)
FastAPI
FastAPI with Uvicorn — bind to all interfaces:
uvicorn main:app --host 0.0.0.0 --port 8000 # Or with --proxy-headers to trust forwarded headers uvicorn main:app --host 0.0.0.0 --port 8000 --proxy-headers
For CORS (if called from a frontend on a different Hatch domain):
from fastapi.middleware.cors import CORSMiddleware
app.add_middleware(
CORSMiddleware,
allow_origins=["https://app.test"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)Project config
# .hatch.yaml
domains:
- domain: api.test
port: 8000
https: true