INNER CODE UNIT · Python

_cors_allow_origins

wzn1118/AsteriaAnalyst · backend/app/main.py:99

def _cors_allow_origins() -> list[str]:
    configured = os.getenv("ASTERIA_CORS_ALLOW_ORIGINS", "")
    origins = [item.strip().rstrip("/") for item in configured.split(",") if item.strip()]
    return origins or ["http://localhost:3000", "http://127.0.0.1:3000"]


def _cors_allow_origin_regex() -> str | None:
    return os.getenv("ASTERIA_CORS_ALLOW_ORIGIN_REGEX") or r"https?://(?:localhost|127\.0\.0\.1)(?::\d+)?"


app.add_middleware(
    CORSMiddleware,
    allow_origins=_cors_allow_origins(),
    allow_origin_regex=_cors_allow_origin_regex(),
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…