Files
weibo_signin/backend/shared/config.py

45 lines
1.3 KiB
Python
Raw Normal View History

2026-03-09 14:05:00 +08:00
"""
Shared configuration for all Weibo-HotSign backend services.
Loads settings from environment variables using pydantic-settings.
"""
from pydantic_settings import BaseSettings
2026-03-09 16:10:29 +08:00
from typing import Optional
2026-03-09 14:05:00 +08:00
class SharedSettings(BaseSettings):
"""Shared settings across all backend services."""
2026-03-09 16:10:29 +08:00
# Database (默认使用 SQLite生产环境可配置为 MySQL)
DATABASE_URL: str = "sqlite+aiosqlite:///../weibo_hotsign.db"
#mysql+aiomysql://root:password@localhost/weibo_hotsign
# Redis (可选,本地开发可以不使用)
REDIS_URL: Optional[str] = None
USE_REDIS: bool = False # 是否启用 Redis
2026-03-09 14:05:00 +08:00
# JWT
JWT_SECRET_KEY: str = "change-me-in-production"
JWT_ALGORITHM: str = "HS256"
JWT_EXPIRATION_HOURS: int = 24
# Cookie encryption
COOKIE_ENCRYPTION_KEY: str = "change-me-in-production"
# 微信小程序
WX_APPID: str = ""
WX_SECRET: str = ""
2026-03-09 16:10:29 +08:00
# Environment
ENVIRONMENT: str = "development"
2026-03-09 14:05:00 +08:00
class Config:
case_sensitive = True
2026-03-17 13:01:51 +08:00
# Docker 环境下不读 .env 文件,靠 docker-compose environment 注入
# 本地开发时 .env 文件仍然生效
2026-03-09 14:05:00 +08:00
env_file = ".env"
2026-03-17 13:01:51 +08:00
env_file_encoding = "utf-8"
extra = "ignore"
2026-03-09 14:05:00 +08:00
shared_settings = SharedSettings()