diff --git a/backend/app.py b/backend/app.py index 8505985..b4b5d04 100644 --- a/backend/app.py +++ b/backend/app.py @@ -21,10 +21,13 @@ import json import logging import time from contextlib import asynccontextmanager +from pathlib import Path from typing import Optional from fastapi import FastAPI, HTTPException, Header, Depends from fastapi.middleware.cors import CORSMiddleware +from fastapi.responses import FileResponse +from fastapi.staticfiles import StaticFiles from pydantic import BaseModel import config as cfg_mod @@ -33,6 +36,8 @@ import upstream as up import poller from crypto import encode_our_cdk, decode_our_cdk, key_from_hex +FRONTEND_DIR = Path(__file__).parent.parent / "frontend" + logging.basicConfig(level=logging.INFO) logger = logging.getLogger("app") @@ -59,6 +64,18 @@ app.add_middleware( allow_headers=["*"], ) +# 前端静态文件(index.html / admin.html 等) +if FRONTEND_DIR.exists(): + app.mount("/static", StaticFiles(directory=str(FRONTEND_DIR)), name="static") + +@app.get("/") +def serve_index(): + return FileResponse(str(FRONTEND_DIR / "index.html")) + +@app.get("/admin") +def serve_admin(): + return FileResponse(str(FRONTEND_DIR / "admin.html")) + # ─── 鉴权依赖 ───────────────────────────────────────────────────────────────── diff --git a/backend/requirements.txt b/backend/requirements.txt index 9c5e926..a77326d 100644 --- a/backend/requirements.txt +++ b/backend/requirements.txt @@ -3,3 +3,4 @@ uvicorn[standard]>=0.29.0 pydantic>=2.0.0 requests>=2.31.0 pycryptodome>=3.20.0 +aiofiles>=23.0.0