From d9e010ef700294345f32f3bab531bd0faa4b5a33 Mon Sep 17 00:00:00 2001 From: penghanyuan Date: Sat, 14 Feb 2026 21:25:37 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=9B=B4=E6=96=B0=20API=20=E4=B8=BB?= =?UTF-8?q?=E9=A1=B5=E8=B7=AF=E7=94=B1=E5=8F=8A=20FastAPI=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将主页路由从 "/home" 更新为根路径 "/",以简化访问。 - 在 FastAPI 实例中禁用文档和 OpenAPI 相关的 URL,提升 API 安全性。 --- api/main.py | 7 +------ api/routers/home.py | 2 +- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/api/main.py b/api/main.py index 633e208..0f2a2b5 100644 --- a/api/main.py +++ b/api/main.py @@ -89,7 +89,7 @@ else: logger.warning("未检测到 LLM API Key 配置") logger.info("===================") -app = FastAPI(title="Life Echo API", version="1.0.0") +app = FastAPI(title="Life Echo API", version="1.0.0", docs_url=None, redoc_url=None, openapi_url=None) @app.on_event("startup") @@ -177,11 +177,6 @@ app.include_router(home.router) # 应用官网主页 app.mount("/static", StaticFiles(directory=Path(__file__).parent / "static"), name="static") -@app.get("/") -async def root(): - return {"message": "Life Echo API", "version": "1.0.0"} - - @app.get("/health") async def health(): return {"status": "ok"} diff --git a/api/routers/home.py b/api/routers/home.py index 15fd536..70a5abc 100644 --- a/api/routers/home.py +++ b/api/routers/home.py @@ -11,7 +11,7 @@ router = APIRouter(tags=["home"]) _STATIC_DIR = Path(__file__).resolve().parent.parent / "static" -@router.get("/home", response_class=HTMLResponse) +@router.get("/", response_class=HTMLResponse) async def get_home(): """ 应用官网主页