Files
xiaoxia-saas/apps/api/app/config.py
T
Xiaoxia AI 015fe3d507 feat(config): add database switch between InMemory and PostgreSQL
- Add USE_IN_MEMORY_DB config flag
- Auto-select repository implementation based on config
- InMemory: for development and testing (no setup needed)
- PostgreSQL: for production (persistent data)
- Update DependencyContainer to support both
- Add documentation for switching databases
- Update .env.example with new config

Phase 4 Task 36/68 completed
2026-06-17 08:25:20 +08:00

58 lines
1.4 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
# 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()