from fastapi import FastAPI from fastapi.staticfiles import StaticFiles from fastapi.responses import HTMLResponse from fastapi.middleware.cors import CORSMiddleware from pathlib import Path app = FastAPI(title="24点游戏计算器") # 添加CORS中间件 app.add_middleware( CORSMiddleware, allow_origins=["*"], # 允许所有来源 allow_credentials=True, allow_methods=["*"], # 允许所有方法 allow_headers=["*"], # 允许所有头 ) # 创建静态文件目录 static_dir = Path(__file__).parent.parent / "static" # 挂载静态文件 app.mount("/static", StaticFiles(directory=str(static_dir)), name="static") from routes import api app.include_router(api.router, prefix="/api") @app.get("/", response_class=HTMLResponse) async def get_index(): """返回主页HTML""" html_path = static_dir / "index.html" if html_path.exists(): with open(html_path, encoding="utf-8") as f: return f.read() else: return """
输入4个1-13之间的数字,查询所有可能的24点解法
请输入4个数字并点击"计算解法"按钮