| from dataclasses import dataclass |
| from pathlib import Path |
| import os |
|
|
|
|
| def _load_env_file() -> None: |
| env_path = Path(__file__).resolve().parents[1] / ".env" |
| if not env_path.exists(): |
| return |
|
|
| for raw_line in env_path.read_text(encoding="utf-8").splitlines(): |
| line = raw_line.strip() |
| if not line or line.startswith("#") or "=" not in line: |
| continue |
|
|
| key, value = line.split("=", 1) |
| key = key.strip() |
| value = value.strip().strip('"').strip("'") |
|
|
| if key and key not in os.environ: |
| os.environ[key] = value |
|
|
|
|
| _load_env_file() |
|
|
|
|
| def _as_bool(value: str | None, default: bool = False) -> bool: |
| if value is None: |
| return default |
| return value.strip().lower() in {"1", "true", "yes", "on"} |
|
|
|
|
| @dataclass(frozen=True) |
| class Settings: |
| app_name: str = os.getenv("APP_NAME", "QueryRoute Dashboard") |
| environment: str = os.getenv("ENVIRONMENT", "development") |
| debug: bool = _as_bool(os.getenv("DEBUG"), False) |
| database_url: str = os.getenv("DATABASE_URL", "") |
| database_url_direct: str = os.getenv("DATABASE_URL_DIRECT", "") |
| jwt_secret_key: str = os.getenv("JWT_SECRET_KEY", "change-me-in-production") |
| jwt_algorithm: str = os.getenv("JWT_ALGORITHM", "HS256") |
| access_token_expire_minutes: int = int( |
| os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", "60") |
| ) |
|
|
|
|
| settings = Settings() |
|
|