mirror of
https://github.com/vee1e/bulk-questionnaire-upload.git
synced 2026-09-01 09:50:06 +00:00
fix: add fallback CORS middleware to guarantee Access-Control-Allow-Origin
CORSMiddleware only fires when Origin header reaches the app. Cloudflare or proxy layers can strip it before the middleware sees it. The fallback http middleware ensures the header is always present when Origin is in the request. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
fc74d0b539
commit
afc9f6b06d
1 changed files with 10 additions and 0 deletions
|
|
@ -36,6 +36,16 @@ app.add_middleware(
|
|||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
@app.middleware("http")
|
||||
async def add_cors_header(request: Request, call_next):
|
||||
response = await call_next(request)
|
||||
origin = request.headers.get("origin", "")
|
||||
if origin and "access-control-allow-origin" not in response.headers:
|
||||
response.headers["access-control-allow-origin"] = "*"
|
||||
response.headers["access-control-allow-methods"] = "GET, POST, PUT, DELETE, OPTIONS"
|
||||
response.headers["access-control-allow-headers"] = "*"
|
||||
return response
|
||||
|
||||
db_service = DatabaseService()
|
||||
|
||||
METRICS_FILE = os.path.join(os.path.dirname(__file__), 'metrics.txt')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue