
- Set up project structure with FastAPI and SQLAlchemy - Configure SQLite database with async support - Implement CRUD endpoints for items resource - Add health endpoint for monitoring - Set up Alembic migrations - Create comprehensive documentation generated with BackendIM... (backend.im)
29 lines
920 B
Python
29 lines
920 B
Python
from typing import List, Optional, Union
|
|
from pathlib import Path
|
|
from pydantic import AnyHttpUrl, validator
|
|
from pydantic_settings import BaseSettings
|
|
|
|
class Settings(BaseSettings):
|
|
API_V1_STR: str = "/api/v1"
|
|
PROJECT_NAME: str = "Quick REST API Service"
|
|
|
|
# CORS settings
|
|
BACKEND_CORS_ORIGINS: List[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)
|
|
|
|
# Database settings
|
|
DB_DIR = Path("/app/storage/db")
|
|
DB_DIR.mkdir(parents=True, exist_ok=True)
|
|
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
|
|
|
|
class Config:
|
|
case_sensitive = True
|
|
|
|
settings = Settings() |