Spaces:
Sleeping
Sleeping
fix: improve CORS origin handling with warnings for production and defaults for development
Browse files- app/main.py +8 -1
app/main.py
CHANGED
|
@@ -25,9 +25,16 @@ logger = get_logger(__name__)
|
|
| 25 |
def _load_origins() -> list[str]:
|
| 26 |
raw = os.getenv("CROWNCODE_CORS_ORIGINS") or os.getenv("CORS_ORIGIN") or "http://localhost:3000"
|
| 27 |
if raw.strip() == "*":
|
| 28 |
-
logger.warning(
|
|
|
|
|
|
|
|
|
|
| 29 |
return ["*"]
|
| 30 |
origins = [origin.strip() for origin in raw.split(",") if origin.strip()]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
logger.info(f"CORS configured for origins: {origins}")
|
| 32 |
return origins
|
| 33 |
|
|
|
|
| 25 |
def _load_origins() -> list[str]:
|
| 26 |
raw = os.getenv("CROWNCODE_CORS_ORIGINS") or os.getenv("CORS_ORIGIN") or "http://localhost:3000"
|
| 27 |
if raw.strip() == "*":
|
| 28 |
+
logger.warning(
|
| 29 |
+
"CORS wildcard '*' is not recommended for production. "
|
| 30 |
+
"Set CROWNCODE_CORS_ORIGINS to an explicit origin list."
|
| 31 |
+
)
|
| 32 |
return ["*"]
|
| 33 |
origins = [origin.strip() for origin in raw.split(",") if origin.strip()]
|
| 34 |
+
if not origins:
|
| 35 |
+
# No origins configured — default to localhost for development
|
| 36 |
+
origins = ["http://localhost:3000"]
|
| 37 |
+
logger.warning("No CORS origins configured, defaulting to localhost")
|
| 38 |
logger.info(f"CORS configured for origins: {origins}")
|
| 39 |
return origins
|
| 40 |
|