From 0b72ed20bca6d90db4114763fb91b7d05bbc82f1 Mon Sep 17 00:00:00 2001 From: lids <1713278948@qq.com> Date: Thu, 7 May 2026 16:33:54 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5web=E5=85=A5=E5=8F=A3?= =?UTF-8?q?=E6=9A=B4=E9=9C=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/main.py | 18 +++++++++++------- static/{chat.html => index.html} | 0 2 files changed, 11 insertions(+), 7 deletions(-) rename static/{chat.html => index.html} (100%) diff --git a/app/main.py b/app/main.py index 788b735..f2dff17 100644 --- a/app/main.py +++ b/app/main.py @@ -3,8 +3,11 @@ FastAPI 主应用 """ from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware +from fastapi.staticfiles import StaticFiles +from fastapi.responses import FileResponse from app.config import settings from app.api import router +import os # 创建 FastAPI 应用实例 @@ -26,16 +29,17 @@ app.add_middleware( # 注册路由 app.include_router(router, prefix="/api/v1", tags=["AI Chat"]) +# 获取 static 目录的绝对路径 +static_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "static") + +# 挂载静态文件目录 +app.mount("/static", StaticFiles(directory=static_dir), name="static") + @app.get("/") async def root(): - """根路径""" - return { - "message": f"欢迎使用 {settings.app_name}", - "version": settings.app_version, - "docs": "/docs", - "redoc": "/redoc" - } + """根路径 - 返回主页""" + return FileResponse(os.path.join(static_dir, "index.html")) @app.get("/health") diff --git a/static/chat.html b/static/index.html similarity index 100% rename from static/chat.html rename to static/index.html