import os from pathlib import Path from typing import List from pydantic_settings import BaseSettings class Settings(BaseSettings): # Project settings PROJECT_NAME: str = "E-Commerce API" PROJECT_DESCRIPTION: str = "FastAPI E-Commerce Application" PROJECT_VERSION: str = "0.1.0" # API settings API_V1_STR: str = "/api/v1" # JWT Settings JWT_SECRET_KEY: str = os.environ.get("JWT_SECRET_KEY", "supersecretkey") JWT_ALGORITHM: str = "HS256" ACCESS_TOKEN_EXPIRE_MINUTES: int = 30 # Database settings DB_DIR: Path = Path("/app") / "storage" / "db" SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite" # CORS settings CORS_ORIGINS: List[str] = [ # Local development "http://localhost", "http://localhost:3000", "http://127.0.0.1", "http://127.0.0.1:3000", # Vercel frontend "https://v0-ecommerce-app-build-swart.vercel.app", # Other common Vercel domains (in case of redirects or preview deployments) "https://*.vercel.app", # Wildcard as a fallback (less secure but helps with debugging) "*" ] # Whether to use only the custom CORS middleware USE_CUSTOM_CORS_ONLY: bool = True # Security settings PASSWORD_HASH_ROUNDS: int = 12 class Config: env_file = ".env" case_sensitive = True # Create DB directory if it doesn't exist Settings().DB_DIR.mkdir(parents=True, exist_ok=True) settings = Settings()