Files
NexaPantry/backend/app/core/config.py
nessi 10a06791db
Some checks failed
CI / backend (push) Successful in 23s
CI / frontend (push) Successful in 41s
CI / docker (push) Failing after 56s
fix: support comma-separated CORS_ORIGINS environment variable
Add NoDecode annotation to cors_origins field in Settings to properly parse comma-separated values from environment variables. Add test to verify CORS_ORIGINS accepts comma-separated list.
2026-06-04 10:43:15 +02:00

36 lines
1.1 KiB
Python

from functools import lru_cache
from typing import Annotated
from pydantic import field_validator
from pydantic_settings import BaseSettings, NoDecode, SettingsConfigDict
class Settings(BaseSettings):
app_env: str = "production"
instance_url: str = "http://localhost"
frontend_origin: str = "http://localhost"
database_url: str = "postgresql+psycopg://nexapantry:nexapantry@localhost:5432/nexapantry"
redis_url: str | None = None
jwt_secret_key: str
settings_secret_key: str
cookie_secure: bool = True
cors_origins: Annotated[list[str], NoDecode] = ["http://localhost"]
log_level: str = "INFO"
default_timezone: str = "Europe/Vienna"
daily_worker_interval_seconds: int = 300
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore")
@field_validator("cors_origins", mode="before")
@classmethod
def parse_origins(cls, value: str | list[str]) -> list[str]:
if isinstance(value, str):
return [origin.strip() for origin in value.split(",") if origin.strip()]
return value
@lru_cache
def get_settings() -> Settings:
return Settings()