f8742351e3
- Add comprehensive environment configuration guide - Create .env.development for development setup - Create .env.production.example as production template - Add LOG_LEVEL configuration to Settings - Add .env.production to .gitignore - Support multiple environments: dev/test/staging/prod - Include security best practices and checklists Phase 4 Task 43/68 completed
59 lines
1.5 KiB
Python
59 lines
1.5 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"
|
|
USE_IN_MEMORY_DB: bool = False # True = 使用内存数据库,False = 使用 PostgreSQL
|
|
|
|
# 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
|
|
LOG_LEVEL: str = "INFO" # DEBUG, INFO, WARNING, ERROR
|
|
|
|
# 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()
|