| 1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- # app/config.py
- import os
- from typing import List
- import secrets
- from dotenv import load_dotenv
-
- # 加载环境变量
- load_dotenv()
-
- class Settings:
- # 项目配置
- PROJECT_NAME: str = os.getenv("PROJECT_NAME", "CaiYouHui 采油会")
- VERSION: str = os.getenv("VERSION", "1.0.0")
- API_V1_PREFIX: str = os.getenv("API_V1_PREFIX", "/api/v1")
-
- # 安全配置
- SECRET_KEY: str = os.getenv("SECRET_KEY", secrets.token_urlsafe(32))
- ALGORITHM: str = os.getenv("ALGORITHM", "HS256")
- ACCESS_TOKEN_EXPIRE_MINUTES: int = int(os.getenv("ACCESS_TOKEN_EXPIRE_MINUTES", "1440")) # 24小时
-
- # 数据库配置 - SQLite
- DATABASE_URL: str = os.getenv("DATABASE_URL", "sqlite:///./caiyouhui.db")
-
- # CORS 配置
- BACKEND_CORS_ORIGINS: List[str] = os.getenv(
- "BACKEND_CORS_ORIGINS",
- "http://localhost:3000,http://localhost:5173"
- ).split(",")
-
- # 调试模式
- DEBUG: bool = os.getenv("DEBUG", "True").lower() == "true"
-
- # 文件上传
- UPLOAD_DIR: str = os.getenv("UPLOAD_DIR", "./uploads")
- MAX_UPLOAD_SIZE: int = int(os.getenv("MAX_UPLOAD_SIZE", "10485760")) # 10MB
-
- # 邮箱验证(可选,后续添加)
- SMTP_ENABLED: bool = os.getenv("SMTP_ENABLED", "False").lower() == "true"
- SMTP_HOST: str = os.getenv("SMTP_HOST", "")
- SMTP_PORT: int = int(os.getenv("SMTP_PORT", "587"))
- SMTP_USER: str = os.getenv("SMTP_USER", "")
- SMTP_PASSWORD: str = os.getenv("SMTP_PASSWORD", "")
-
- settings = Settings()
|