From 75dd3d875ab05abd7e783b59aeeabff621587e04 Mon Sep 17 00:00:00 2001 From: nosqli Date: Tue, 21 Apr 2026 00:35:51 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20FastAPI=20=E6=8C=82=E8=BD=BD=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E9=9D=99=E6=80=81=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - GET / -> frontend/index.html 客户充值页 - GET /admin -> frontend/admin.html 管理后台 - /static/* -> frontend/ 目录静态资源 - requirements.txt 补充 aiofiles 依赖 Co-Authored-By: Claude Sonnet 4.6 (1M context) --- backend/app.py | 17 +++++++++++++++++ backend/requirements.txt | 1 + 2 files changed, 18 insertions(+) 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