"""Application configuration. Settings are read from environment variables so the same code runs locally, in Docker (see ``docker-compose.yml``) and in CI. See ``.env.example`` for the documented variable set. """ import os from functools import lru_cache # --- Application metadata ------------------------------------------------- APP_NAME = "newzy" APP_VERSION = "0.1.0" API_V1_PREFIX = "/api/v1" # Default location of the SQLite database file (relative to the working # directory). In Docker this resolves inside the mounted volume # (``./data/db`` -> ``/app/data/db`` on the host's ``./data/db``). DEFAULT_DATABASE_URL = "sqlite:///./data/db/newzy.db" # Default origins allowed by CORS (frontend dev servers). DEFAULT_CORS_ORIGINS = "http://localhost:3000,http://127.0.0.1:3000" # Default JWT signing key (override via HN_SECRET_KEY in production — # never run a public deployment with the dev default). DEFAULT_SECRET_KEY = "newzy-dev-secret-change-me" class Settings: """Runtime settings loaded from the environment.""" def __init__(self) -> None: self.database_url: str = os.getenv("DATABASE_URL", DEFAULT_DATABASE_URL) self.cors_origins: list[str] = [ origin.strip() for origin in os.getenv("CORS_ORIGINS", DEFAULT_CORS_ORIGINS).split(",") if origin.strip() ] # JWT signing key for auth tokens (see core.auth). self.secret_key: str = os.getenv("HN_SECRET_KEY", DEFAULT_SECRET_KEY) @property def is_sqlite(self) -> bool: """True when the configured database is SQLite.""" return self.database_url.startswith("sqlite") @lru_cache def get_settings() -> Settings: """Return the cached application settings.""" return Settings()