refactor: 后端从Node.js重写为Python FastAPI
This commit is contained in:
37
server/app/config.py
Normal file
37
server/app/config.py
Normal file
@@ -0,0 +1,37 @@
|
||||
"""
|
||||
配置管理
|
||||
"""
|
||||
from pydantic_settings import BaseSettings
|
||||
from functools import lru_cache
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""应用配置"""
|
||||
# 数据库配置
|
||||
db_host: str = "localhost"
|
||||
db_port: int = 3306
|
||||
db_user: str = "root"
|
||||
db_password: str = ""
|
||||
db_name: str = "stardom_story"
|
||||
|
||||
# 服务配置
|
||||
server_host: str = "0.0.0.0"
|
||||
server_port: int = 3000
|
||||
debug: bool = True
|
||||
|
||||
# AI服务配置(预留)
|
||||
openai_api_key: str = ""
|
||||
openai_base_url: str = "https://api.openai.com/v1"
|
||||
|
||||
@property
|
||||
def database_url(self) -> str:
|
||||
return f"mysql+aiomysql://{self.db_user}:{self.db_password}@{self.db_host}:{self.db_port}/{self.db_name}"
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
env_file_encoding = "utf-8"
|
||||
|
||||
|
||||
@lru_cache()
|
||||
def get_settings() -> Settings:
|
||||
return Settings()
|
||||
Reference in New Issue
Block a user