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

51
server/app/main.py Normal file
View File

@@ -0,0 +1,51 @@
"""
星域故事汇 - Python后端服务
"""
import uvicorn
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.config import get_settings
from app.routers import story, user
settings = get_settings()
# 创建应用
app = FastAPI(
title="星域故事汇",
description="互动故事小游戏后端服务",
version="1.0.0"
)
# 跨域配置
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# 注册路由
app.include_router(story.router, prefix="/api/stories", tags=["故事"])
app.include_router(user.router, prefix="/api/user", tags=["用户"])
@app.get("/")
async def root():
return {"message": "星域故事汇后端服务运行中", "version": "1.0.0"}
@app.get("/health")
async def health_check():
return {"status": "ok"}
if __name__ == "__main__":
print(f"星域故事汇服务器运行在 http://localhost:{settings.server_port}")
uvicorn.run(
"app.main:app",
host=settings.server_host,
port=settings.server_port,
reload=settings.debug
)