CaiYouHui后端fastapi实现

config.py 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # app/config.py
  2. import os
  3. from typing import List
  4. import secrets
  5. from dotenv import load_dotenv
  6. # 加载环境变量
  7. load_dotenv()
  8. class Settings:
  9. # 项目配置
  10. PROJECT_NAME: str = os.getenv("PROJECT_NAME", "CaiYouHui 采油会")
  11. VERSION: str = os.getenv("VERSION", "1.0.0")
  12. # API配置
  13. API_V1_PREFIX: str = os.getenv("API_V1_PREFIX", "/api/v1")
  14. APP_RUN_PORT: int = int(os.getenv("APP_RUN_PORT", "10003"))
  15. # 安全配置
  16. SECRET_KEY: str = os.getenv("SECRET_KEY", secrets.token_urlsafe(32))
  17. ALGORITHM: str = os.getenv("ALGORITHM", "HS256")
  18. ACCESS_TOKEN_EXPIRE_MINUTES: int = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", "1440")) # 24小时
  19. # 数据库配置 - SQLite
  20. DATABASE_URL: str = os.getenv("DATABASE_URL", "sqlite+aiosqlite:///./caiyouhui.db")
  21. # CORS 配置
  22. BACKEND_CORS_ORIGINS: List[str] = os.getenv(
  23. "BACKEND_CORS_ORIGINS",
  24. "http://localhost:3000,http://localhost:5173"
  25. ).split(",")
  26. # 调试模式
  27. DEBUG: bool = os.getenv("DEBUG", "True").lower() == "true"
  28. # 日志配置
  29. LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO")
  30. LOG_FILE: str = os.getenv("LOG_FILE", "logs/app.log")
  31. # 文件上传
  32. UPLOAD_DIR: str = os.getenv("UPLOAD_DIR", "./uploads")
  33. MAX_UPLOAD_SIZE: int = int(os.getenv("MAX_UPLOAD_SIZE", "10485760")) # 10MB
  34. # 性能配置
  35. DATABASE_POOL_SIZE: int = 20
  36. DATABASE_MAX_OVERFLOW: int = 10
  37. # 邮箱验证(可选,后续添加)
  38. SMTP_ENABLED: bool = os.getenv("SMTP_ENABLED", "False").lower() == "true"
  39. SMTP_HOST: str = os.getenv("SMTP_HOST", "")
  40. SMTP_PORT: int = int(os.getenv("SMTP_PORT", "587"))
  41. SMTP_USER: str = os.getenv("SMTP_USER", "")
  42. SMTP_PASSWORD: str = os.getenv("SMTP_PASSWORD", "")
  43. settings = Settings()