refactor: 后端从Node.js重写为Python FastAPI

This commit is contained in:
wangwuww111
2026-03-04 18:31:48 +08:00
parent 729bb3aaeb
commit ac0accdde6
40 changed files with 1096 additions and 2035 deletions

37
server/app/config.py Normal file
View 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()