anderson-ufrj
commited on
Commit
·
05ab472
1
Parent(s):
7b9a6bc
fix: disable TrustedHostMiddleware for HuggingFace Spaces compatibility
Browse filesThe middleware was causing 400 Bad Request errors due to proxy header issues
- src/api/app.py +12 -11
src/api/app.py
CHANGED
|
@@ -12,7 +12,7 @@ from typing import Dict, Any
|
|
| 12 |
|
| 13 |
from fastapi import FastAPI, HTTPException, Depends, BackgroundTasks
|
| 14 |
from fastapi.middleware.cors import CORSMiddleware
|
| 15 |
-
from fastapi.middleware.trustedhost import TrustedHostMiddleware
|
| 16 |
from fastapi.responses import JSONResponse
|
| 17 |
from fastapi.openapi.docs import get_swagger_ui_html
|
| 18 |
from fastapi.openapi.utils import get_openapi
|
|
@@ -128,16 +128,17 @@ app.add_middleware(
|
|
| 128 |
)
|
| 129 |
|
| 130 |
# Add trusted host middleware for production
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
|
|
|
| 141 |
|
| 142 |
# CORS middleware with secure configuration
|
| 143 |
app.add_middleware(
|
|
|
|
| 12 |
|
| 13 |
from fastapi import FastAPI, HTTPException, Depends, BackgroundTasks
|
| 14 |
from fastapi.middleware.cors import CORSMiddleware
|
| 15 |
+
# from fastapi.middleware.trustedhost import TrustedHostMiddleware # Disabled for HuggingFace
|
| 16 |
from fastapi.responses import JSONResponse
|
| 17 |
from fastapi.openapi.docs import get_swagger_ui_html
|
| 18 |
from fastapi.openapi.utils import get_openapi
|
|
|
|
| 128 |
)
|
| 129 |
|
| 130 |
# Add trusted host middleware for production
|
| 131 |
+
# DISABLED for HuggingFace Spaces - causes issues with proxy headers
|
| 132 |
+
# if settings.app_env == "production":
|
| 133 |
+
# app.add_middleware(
|
| 134 |
+
# TrustedHostMiddleware,
|
| 135 |
+
# allowed_hosts=["api.cidadao.ai", "*.cidadao.ai", "*.hf.space", "*.huggingface.co"]
|
| 136 |
+
# )
|
| 137 |
+
# else:
|
| 138 |
+
# app.add_middleware(
|
| 139 |
+
# TrustedHostMiddleware,
|
| 140 |
+
# allowed_hosts=["localhost", "127.0.0.1", "*.cidadao.ai", "testserver"]
|
| 141 |
+
# )
|
| 142 |
|
| 143 |
# CORS middleware with secure configuration
|
| 144 |
app.add_middleware(
|