Sid-WC121
initial
c21180c
Raw History Blame Contribute Delete
1.38 kB
"""Application settings loaded from environment variables."""
from __future__ import annotations
import os
from dataclasses import dataclass, field
def _parse_cors_origins() -> list[str]:
"""Parse CORS_ORIGINS env var into a list of origins.
Handles these patterns:
CORS_ORIGINS=* → ["*"]
CORS_ORIGINS=http://localhost:5173,http://localhost:3000 → split by comma
CORS_ORIGINS not set → sensible dev defaults
"""
raw = os.getenv("CORS_ORIGINS", "").strip()
if raw == "*":
return ["*"]
if raw:
return [origin.strip() for origin in raw.split(",") if origin.strip()]
# Default: local development origins
return ["http://localhost:5173", "http://localhost:3000"]
@dataclass
class Settings:
data_dir: str = os.getenv("DATA_DIR", "datasets")
checkpoint_dir: str = os.getenv("CHECKPOINT_DIR", "checkpoints")
max_upload_size: int = int(os.getenv("MAX_UPLOAD_SIZE", str(500 * 1024 * 1024)))
preview_rows: int = int(os.getenv("PREVIEW_ROWS", "50"))
sample_rows: int = int(os.getenv("SAMPLE_ROWS", "10000"))
cors_origins: list[str] = field(
default_factory=lambda: _parse_cors_origins()
)
host: str = os.getenv("HOST", "0.0.0.0")
port: int = int(os.getenv("PORT", "8000"))
settings = Settings()