Automated Action c1c91cc80f Fix OpenAPI documentation in production environment
- Move OpenAPI schema to root path for easier access
- Add ROOT_PATH setting to support deployments behind proxies
- Add root route that redirects to documentation
2025-05-26 11:31:16 +00:00

41 lines
1.1 KiB
Python

from typing import List
from pydantic import field_validator
from pydantic_settings import BaseSettings
from pathlib import Path
class Settings(BaseSettings):
PROJECT_NAME: str = "E-Commerce API"
VERSION: str = "0.1.0"
API_V1_STR: str = "/api/v1"
ROOT_PATH: str = "" # For deployments behind proxies/subpaths, can be set via env var
# CORS Settings
CORS_ORIGINS: List[str] = ["*"] # Allow all origins for development
@field_validator("CORS_ORIGINS", mode="before")
@classmethod
def validate_cors_origins(cls, v):
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)
# JWT Settings
SECRET_KEY: str = "supersecretkey" # Change in production
ALGORITHM: str = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
# Database Settings
DB_DIR: Path = Path("/app") / "storage" / "db"
class Config:
env_file = ".env"
case_sensitive = True
settings = Settings()
# Ensure DB directory exists
settings.DB_DIR.mkdir(parents=True, exist_ok=True)