diff options
author | 2024-08-19 17:23:06 +0100 | |
---|---|---|
committer | 2024-08-19 17:23:06 +0100 | |
commit | 55643551a66ad429ee3bf309c4d3751ea5f51671 (patch) | |
tree | 1d53bf0920ecb2b62ad829d504dba07a093f5198 /thallium-backend | |
parent | Add CORS environment variables to settings (diff) |
backend: Add CORSMiddleware to allow CORS requests from Thallium Frontend
Diffstat (limited to 'thallium-backend')
-rw-r--r-- | thallium-backend/src/app.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/thallium-backend/src/app.py b/thallium-backend/src/app.py index 311e336..3f65631 100644 --- a/thallium-backend/src/app.py +++ b/thallium-backend/src/app.py @@ -5,6 +5,7 @@ from collections.abc import Awaitable, Callable from fastapi import FastAPI, Request, Response from fastapi.exceptions import RequestValidationError +from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import HTMLResponse, JSONResponse from fastapi.staticfiles import StaticFiles from scalar_fastapi import get_scalar_api_reference @@ -25,6 +26,14 @@ fastapi_app = FastAPI( fastapi_app.include_router(top_level_router) fastapi_app.mount("/static", StaticFiles(directory="src/static"), name="static") +fastapi_app.add_middleware( + CORSMiddleware, + allow_origins=CONFIG.cors_origins, + allow_credentials=True, + allow_methods=["GET", "POST", "PUT", "DELETE", "OPTIONS"], + allow_headers=["*"], +) + @fastapi_app.get("/heartbeat") def health_check() -> JSONResponse: |