config.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. """
  2. Application configuration using Pydantic Settings.
  3. Environment variables are loaded from .env file.
  4. """
  5. from pydantic_settings import BaseSettings, SettingsConfigDict
  6. class Settings(BaseSettings):
  7. """Application settings loaded from environment variables."""
  8. # Database
  9. DATABASE_URL: str
  10. # Redis
  11. REDIS_URL: str = "redis://localhost:6379/0"
  12. # Security
  13. SECRET_KEY: str
  14. ACCESS_TOKEN_EXPIRE_MINUTES: int = 15
  15. REFRESH_TOKEN_EXPIRE_DAYS: int = 30
  16. ALGORITHM: str = "HS256"
  17. # CORS
  18. CORS_ORIGINS: str = "http://localhost:5173"
  19. # File Storage
  20. UPLOAD_DIR: str = "/var/lib/mybeacon/uploads"
  21. # Email
  22. SMTP_HOST: str = "localhost"
  23. SMTP_PORT: int = 587
  24. SMTP_USER: str = ""
  25. SMTP_PASSWORD: str = ""
  26. SMTP_FROM: str = "noreply@mybeacon.com"
  27. # Application
  28. DEBUG: bool = False
  29. LOG_LEVEL: str = "INFO"
  30. API_V1_PREFIX: str = "/api/v1"
  31. PROJECT_NAME: str = "MyBeacon API"
  32. model_config = SettingsConfigDict(
  33. env_file=".env",
  34. env_file_encoding="utf-8",
  35. case_sensitive=False
  36. )
  37. @property
  38. def cors_origins_list(self) -> list[str]:
  39. """Parse CORS_ORIGINS string into list."""
  40. return [origin.strip() for origin in self.CORS_ORIGINS.split(",")]
  41. # Global settings instance
  42. settings = Settings()