- Add FastAPI app with title 'Debate API' v1.0.0 - Configure pydantic-settings for environment-based configuration - Create /health endpoint at root level - Create /api/v1/health and /api/v1/health/ready endpoints - Disable docs/redoc in production environment
51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
"""Application configuration via pydantic-settings."""
|
|
|
|
from pydantic_settings import BaseSettings
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""Application settings loaded from environment variables."""
|
|
|
|
# Database
|
|
database_url: str = "postgresql+asyncpg://debate:debate_dev@localhost:5433/debate"
|
|
|
|
# Security
|
|
secret_key: str = "change-me-in-production"
|
|
csrf_secret_key: str = "change-me-in-production"
|
|
|
|
# Environment
|
|
environment: str = "development"
|
|
debug: bool = True
|
|
|
|
# CORS and trusted hosts
|
|
allowed_hosts: str = "localhost,127.0.0.1"
|
|
allowed_origins: str = "http://localhost:3000,http://127.0.0.1:3000"
|
|
|
|
# Cookie settings
|
|
cookie_domain: str = "localhost"
|
|
|
|
@property
|
|
def allowed_hosts_list(self) -> list[str]:
|
|
"""Parse allowed hosts as a list."""
|
|
return [h.strip() for h in self.allowed_hosts.split(",") if h.strip()]
|
|
|
|
@property
|
|
def allowed_origins_list(self) -> list[str]:
|
|
"""Parse allowed origins as a list."""
|
|
return [o.strip() for o in self.allowed_origins.split(",") if o.strip()]
|
|
|
|
@property
|
|
def is_production(self) -> bool:
|
|
"""Check if running in production environment."""
|
|
return self.environment == "production"
|
|
|
|
class Config:
|
|
"""Pydantic settings configuration."""
|
|
|
|
env_file = ".env"
|
|
env_file_encoding = "utf-8"
|
|
extra = "ignore"
|
|
|
|
|
|
# Global settings instance
|
|
settings = Settings()
|