From 9cc280a89205e4fb3aa425dd391ea41b6a4118c1 Mon Sep 17 00:00:00 2001 From: lgh <625458956@qq.com> Date: Sat, 21 Feb 2026 01:49:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=89=8D=E7=AB=AF?= =?UTF-8?q?=E9=9D=99=E6=80=81=E6=96=87=E4=BB=B6=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/main.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/backend/app/main.py b/backend/app/main.py index 66de186..df8d8de 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -1,5 +1,7 @@ from fastapi import FastAPI, Depends, HTTPException, BackgroundTasks from fastapi.middleware.cors import CORSMiddleware +from fastapi.staticfiles import StaticFiles +from fastapi.responses import FileResponse from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy.future import select from typing import List @@ -1140,3 +1142,25 @@ async def update_ai_config(config: LLMConfig): "provider": config.provider, "requires_restart": True } + + +# 前端静态文件服务 +FRONTEND_DIR = Path(__file__).parent.parent / "frontend" / "dist" + +@app.get("/") +async def serve_frontend(): + """服务前端首页""" + index_path = FRONTEND_DIR / "index.html" + if index_path.exists(): + return FileResponse(index_path) + return {"message": "Frontend not found", "frontend_dir": str(FRONTEND_DIR)} + +@app.get("/{path:path}") +async def serve_frontend_paths(path: str): + """服务前端其他路由""" + # 先尝试直接文件 + file_path = FRONTEND_DIR / path + if file_path.exists() and file_path.is_file(): + return FileResponse(file_path) + # 回退到 index.html (SPA 路由) + return FileResponse(FRONTEND_DIR / "index.html")