提交 c6a688e4 authored 作者: 陈泽健's avatar 陈泽健

fix(deploy): 修复容器部署时根路径返回 JSON 而非前端页面

- root() 增加 frontend/dist/ 存在性检查
- 容器部署时返回 index.html,本地开发时返回 JSON 健康检查
- 解决 @app.get("/") 精确匹配抢占 SPA 回退路由的问题
Co-Authored-By: 's avatarClaude <noreply@anthropic.com>
上级 fd2c2f4d
此差异已折叠。
...@@ -152,13 +152,17 @@ app.include_router( ...@@ -152,13 +152,17 @@ app.include_router(
@app.get("/", tags=["健康检查"]) @app.get("/", tags=["健康检查"])
async def root(): async def root():
""" """
根路径健康检查 根路径 — 容器部署时返回前端页面,否则返回健康检查 JSON
返回服务状态信息,用于确认服务正常运行。
Returns: Returns:
dict: 服务状态信息 FileResponse (前端 dist 存在时) 或 dict (健康检查)
""" """
# 容器部署时,前端 dist 存在,直接返回 index.html
FRONTEND_DIST = Path(__file__).parent.parent / "frontend" / "dist"
if FRONTEND_DIST.exists():
return FileResponse(str(FRONTEND_DIST / "index.html"))
# 本地开发时,返回健康检查 JSON
return { return {
"status": "ok", "status": "ok",
"message": f"{settings.APP_NAME} API 服务运行中", "message": f"{settings.APP_NAME} API 服务运行中",
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论