28 lines
810 B
Python
28 lines
810 B
Python
from functools import lru_cache
|
|
from pathlib import Path
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
ENV_ALL_PATH = Path(__file__).resolve().parents[2] / ".env.all"
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
"""集中管理项目配置,来源于 .env.all / 环境变量。"""
|
|
|
|
# 约定:全局仅使用仓库根目录的 .env.all 作为配置来源(生产优先)。
|
|
# 说明:这里使用绝对路径,避免因 cwd 不同导致读取失败。
|
|
model_config = SettingsConfigDict(
|
|
env_file=str(ENV_ALL_PATH), env_file_encoding="utf-8", extra="ignore"
|
|
)
|
|
|
|
frontend_url: str = "http://localhost:3000"
|
|
|
|
|
|
@lru_cache
|
|
def get_settings() -> Settings:
|
|
"""惰性实例化设置,避免重复读取文件。"""
|
|
return Settings()
|
|
|
|
|
|
settings = get_settings()
|