Fix: Disable TrustedHostMiddleware behind Traefik proxy

TrustedHostMiddleware was blocking localhost healthchecks from Traefik,
  causing 400 Bad Request errors. When behind a reverse proxy like
  Traefik/Coolify, host validation is handled by the proxy itself.
This commit is contained in:
richardtekula
2025-11-11 16:41:43 +01:00
parent 6d0ee923e2
commit f9c80c375a

View File

@@ -100,12 +100,14 @@ app.mount("/static", StaticFiles(directory=ADMIN_PANEL_DIR), name="static")
templates = Jinja2Templates(directory=ADMIN_PANEL_DIR) templates = Jinja2Templates(directory=ADMIN_PANEL_DIR)
# Add middleware for production readiness # Add middleware for production readiness
if AppConfig.ENVIRONMENT == "production": # NOTE: TrustedHostMiddleware disabled when behind reverse proxy (Traefik/Coolify)
# Trusted host middleware for production security # The reverse proxy handles host validation
app.add_middleware( # if AppConfig.ENVIRONMENT == "production":
TrustedHostMiddleware, # # Trusted host middleware for production security
allowed_hosts=AppConfig.TRUSTED_HOSTS # app.add_middleware(
) # TrustedHostMiddleware,
# allowed_hosts=AppConfig.TRUSTED_HOSTS
# )
# CORS middleware for cross-origin requests # CORS middleware for cross-origin requests
app.add_middleware( app.add_middleware(