43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
from typing import List, Union
|
|
from pathlib import Path
|
|
|
|
from pydantic import AnyHttpUrl, validator
|
|
from pydantic_settings import BaseSettings
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
# Base project settings
|
|
PROJECT_NAME: str = "SaaS Invoicing Application"
|
|
PROJECT_DESCRIPTION: str = "A SaaS invoicing application backend API"
|
|
PROJECT_VERSION: str = "0.1.0"
|
|
API_V1_STR: str = "/api/v1"
|
|
|
|
# CORS settings
|
|
BACKEND_CORS_ORIGINS: List[Union[str, AnyHttpUrl]] = ["*"]
|
|
|
|
@validator("BACKEND_CORS_ORIGINS", pre=True)
|
|
def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]:
|
|
if isinstance(v, str) and not v.startswith("["):
|
|
return [i.strip() for i in v.split(",")]
|
|
elif isinstance(v, (list, str)):
|
|
return v
|
|
raise ValueError(v)
|
|
|
|
# Security settings
|
|
SECRET_KEY: str = "CHANGE_ME_IN_PRODUCTION" # For JWT token generation
|
|
ALGORITHM: str = "HS256" # For JWT token algorithm
|
|
ACCESS_TOKEN_EXPIRE_MINUTES: int = 60 * 24 * 7 # 7 days
|
|
|
|
# Database settings
|
|
DB_DIR: Path = Path("/app") / "storage" / "db"
|
|
|
|
# Set default values for env variables
|
|
class Config:
|
|
env_file = ".env"
|
|
case_sensitive = True
|
|
|
|
|
|
settings = Settings()
|
|
|
|
# Ensure database directory exists
|
|
settings.DB_DIR.mkdir(parents=True, exist_ok=True) |