Update CORS configuration to support additional origins and regex for local environment
This commit is contained in:
@@ -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=["*"],
|
||||
|
||||
Reference in New Issue
Block a user