Update CORS configuration to support additional origins and regex for local environment

This commit is contained in:
zaid
2026-08-22 17:32:06 +05:30
parent 7ab9cc3bee
commit f519f5727c
2 changed files with 8 additions and 1 deletions
+6
View File
@@ -173,9 +173,15 @@ def create_app() -> FastAPI:
"CORS_ALLOWED_ORIGINS must be set when allow_credentials=True"
)
# Vite hops 5173+ when ports are taken. Local regex covers that without listing every port.
origin_regex = settings.CORS_ALLOW_ORIGIN_REGEX
if settings.APP_ENV == "local" and not origin_regex:
origin_regex = r"https?://(localhost|127\.0\.0\.1):\d+"
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_origin_regex=origin_regex,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],