refactor: 后端从Node.js重写为Python FastAPI
This commit is contained in:
51
server/app/main.py
Normal file
51
server/app/main.py
Normal 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
|
||||
)
|
||||
Reference in New Issue
Block a user