37836b2755
- Create main.py with CORS and GZip middleware - Add Settings class with all configuration options - Support .env file for environment variables - Add health check and root endpoints - Create comprehensive README with quick start guide - Add .env.example template - Include API usage examples and troubleshooting Phase 4 Task 30/68 completed
57 lines
1.3 KiB
Python
57 lines
1.3 KiB
Python
"""
|
|
应用配置
|
|
"""
|
|
import os
|
|
from pydantic_settings import BaseSettings
|
|
from functools import lru_cache
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""应用配置"""
|
|
|
|
# 应用配置
|
|
APP_NAME: str = "小虾 SaaS"
|
|
APP_VERSION: str = "1.0.0"
|
|
BASE_URL: str = "http://localhost:3000"
|
|
|
|
# 数据库配置
|
|
DATABASE_URL: str = "postgresql://xiaoxia:password@localhost:5432/xiaoxia_saas"
|
|
|
|
# Redis 配置
|
|
REDIS_URL: str = "redis://localhost:6379/0"
|
|
|
|
# JWT 配置
|
|
JWT_SECRET_KEY: str = "your-secret-key-change-in-production"
|
|
JWT_ALGORITHM: str = "HS256"
|
|
JWT_ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
|
|
JWT_REFRESH_TOKEN_EXPIRE_DAYS: int = 30
|
|
|
|
# 邮件配置
|
|
SMTP_HOST: str = "smtp.gmail.com"
|
|
SMTP_PORT: int = 587
|
|
SMTP_USER: str = ""
|
|
SMTP_PASSWORD: str = ""
|
|
SMTP_FROM_EMAIL: str = ""
|
|
SMTP_FROM_NAME: str = "小虾 SaaS"
|
|
|
|
# 环境
|
|
ENVIRONMENT: str = "development" # development, staging, production
|
|
DEBUG: bool = True
|
|
|
|
# CORS
|
|
CORS_ORIGINS: list = ["http://localhost:3000", "http://localhost:5173"]
|
|
|
|
class Config:
|
|
env_file = ".env"
|
|
case_sensitive = True
|
|
|
|
|
|
@lru_cache()
|
|
def get_settings() -> Settings:
|
|
"""获取配置(单例)"""
|
|
return Settings()
|
|
|
|
|
|
# 全局配置实例
|
|
settings = get_settings()
|