fix: add root redirect to /docs and show localhost in serve output

This commit is contained in:
2026-07-05 01:19:48 +08:00
parent 30a1c1af57
commit 2f0aa38fbf
2 changed files with 9 additions and 1 deletions
+2 -1
View File
@@ -72,7 +72,8 @@ def search(query: str, top_k: int = 10):
@app.command() @app.command()
def serve(port: int = 8000): def serve(port: int = 8000):
"""启动 HTTP 服务.""" """启动 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) uvicorn.run("src.server.app:app", host="0.0.0.0", port=port, reload=False)
+7
View File
@@ -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") @app.get("/api/v1/health")
def health(): def health():
return {"status": "ok"} return {"status": "ok"}