fix(admin): /health 被误加 /api/v1 前缀,健康状态永远「系统异常」 #17

Merged
WorkBuddy merged 1 commits from fix-healthcheck-url into main 2026-09-22 17:45:49 +08:00
Collaborator

问题

管理后台右上角永远显示「系统异常」,即使一切正常。

根因

  • 后端 /health/health/ready 挂在根路径(app.py,compose healthcheck 也走这里)
  • 前端共享层 lib/http.tsbuild_url所有路径统一加 /api/v1 前缀 → 实际请求 /api/v1/health → 404
  • fetchHealth 吞错返回 {status: "unknown"} → AdminLayout/Monitoring 判定非 healthy → 永远异常

修复

  1. build_url/health/health/* 豁免前缀(其余路径行为不变)
  2. http.test.ts 补 2 个 URL 用例。顺带修复测试基建:该文件此前因 ApiError 构造函数参数属性(public status)不被 node strip-types 支持而完全无法运行,改为显式字段赋值(语义等价)后 7 个用例全部可跑

验证

node --experimental-strip-types src/lib/http.test.ts → 7 passed 0 failed(修复前新用例红)
tsc --noEmit 0 错误

## 问题 管理后台右上角永远显示「系统异常」,即使一切正常。 ## 根因 - 后端 `/health`、`/health/ready` 挂在**根路径**(app.py,compose healthcheck 也走这里) - 前端共享层 `lib/http.ts` 的 `build_url` 把**所有**路径统一加 `/api/v1` 前缀 → 实际请求 `/api/v1/health` → 404 - `fetchHealth` 吞错返回 `{status: "unknown"}` → AdminLayout/Monitoring 判定非 healthy → 永远异常 ## 修复 1. `build_url` 对 `/health` 与 `/health/*` 豁免前缀(其余路径行为不变) 2. `http.test.ts` 补 2 个 URL 用例。**顺带修复测试基建**:该文件此前因 `ApiError` 构造函数参数属性(`public status`)不被 node strip-types 支持而完全无法运行,改为显式字段赋值(语义等价)后 7 个用例全部可跑 ## 验证 `node --experimental-strip-types src/lib/http.test.ts` → 7 passed 0 failed(修复前新用例红) tsc --noEmit 0 错误
WorkBuddy added 1 commit 2026-09-22 14:23:11 +08:00
build_url 对所有路径强制加 /api/v1,但后端 /health 与 /health/ready
挂在根路径(app.py,与 compose healthcheck 一致)→ 前端请求 /api/v1/health
404 → fetchHealth 吞错返回 status=unknown → 右上角/监控页永远「系统异常」。

- build_url 对 /health 与 /health/* 豁免前缀
- http.test.ts 补 URL 豁免用例(该测试此前因 ApiError 参数属性不被
  strip-types 支持而完全无法运行,顺手改为显式赋值使基建可用)
WorkBuddy merged commit 3fc3e91bd3 into main 2026-09-22 17:45:49 +08:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: shangfangjian/Profeto#17