49 lines
1.3 KiB
Python
49 lines
1.3 KiB
Python
"""
|
|
Configuration settings for the application.
|
|
"""
|
|
from pathlib import Path
|
|
from typing import List, Optional, Union
|
|
|
|
from pydantic import AnyHttpUrl, BaseSettings, validator
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""
|
|
Application settings.
|
|
"""
|
|
|
|
PROJECT_NAME: str = "Todo API"
|
|
VERSION: str = "0.1.0"
|
|
API_V1_STR: str = "/api/v1"
|
|
|
|
# BACKEND_CORS_ORIGINS is a comma-separated list of origins
|
|
# e.g: "http://localhost:8000,http://localhost:3000"
|
|
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
|
|
|
|
@validator("BACKEND_CORS_ORIGINS", pre=True)
|
|
def assemble_cors_origins(cls, v: Union[str, List[str]]) -> List[str]:
|
|
"""
|
|
Parse CORS origins from string or list.
|
|
"""
|
|
if isinstance(v, str) and not v.startswith("["):
|
|
return [i.strip() for i in v.split(",")]
|
|
if isinstance(v, (list, str)):
|
|
return v
|
|
raise ValueError(v)
|
|
|
|
# Database configuration
|
|
DB_DIR: Path = Path("/app") / "storage" / "db"
|
|
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
|
|
|
class Config:
|
|
"""
|
|
Config class for Settings.
|
|
"""
|
|
case_sensitive = True
|
|
|
|
|
|
# Create settings instance
|
|
settings = Settings()
|
|
|
|
# Ensure DB directory exists
|
|
settings.DB_DIR.mkdir(parents=True, exist_ok=True) |