From 2f0aa38fbf4a9ca93a760a7a6c4422b49188af0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E8=88=AA=E5=AE=87?= <3364451258@qq.com> Date: Sun, 5 Jul 2026 01:19:48 +0800 Subject: [PATCH] fix: add root redirect to /docs and show localhost in serve output --- src/cli/main.py | 3 ++- src/server/app.py | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/cli/main.py b/src/cli/main.py index 4944172..b161211 100644 --- a/src/cli/main.py +++ b/src/cli/main.py @@ -72,7 +72,8 @@ def search(query: str, top_k: int = 10): @app.command() def serve(port: int = 8000): """启动 HTTP 服务.""" - typer.echo(f"🚀 启动服务: http://0.0.0.0:{port}") + typer.echo(f"🚀 启动服务: http://localhost:{port}") + typer.echo(f"📖 API 文档: http://localhost:{port}/docs") uvicorn.run("src.server.app:app", host="0.0.0.0", port=port, reload=False) diff --git a/src/server/app.py b/src/server/app.py index 338fcce..09ecffc 100644 --- a/src/server/app.py +++ b/src/server/app.py @@ -84,6 +84,13 @@ app = FastAPI( ) +@app.get("/") +def root(): + """根路径重定向到 API 文档.""" + from fastapi.responses import RedirectResponse + return RedirectResponse(url="/docs") + + @app.get("/api/v1/health") def health(): return {"status": "ok"}