from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import HTMLResponse from fastapi.staticfiles import StaticFiles from app.api.routes import router from pathlib import Path from app.core.config import settings app = FastAPI(title="Card Extraction API", version="1.0") app.mount("/static", StaticFiles(directory=settings.STATIC_DIR), name="static") app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"] ) @app.get("/", response_class=HTMLResponse) async def root(): html_path = Path("static/view_results.html") return html_path.read_text(encoding="utf-8") # 注册路由 app.include_router(router, prefix="/api")