fix: add root redirect to /docs and show localhost in serve output
This commit is contained in:
+2
-1
@@ -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)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -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"}
|
||||||
|
|||||||
Reference in New Issue
Block a user