fix: 修复 MarkBase Engine 健康检查状态不匹配问题

问题:
- MarkBase Engine 的 /health 端点返回 JSON 格式 {"status":"ok"}
- testMbe 函数期望纯文本 "OK"
- 导致状态被错误地设置为 offline

修复:
- 使用 Content-Type 判断响应格式
- JSON 格式:解析并检查 status 字段
- 纯文本格式:检查是否为 "OK" 或包含 JSON 状态
- 兼容两种响应格式,确保状态正确

改进:
- 从 JSON 响应中提取 version 和 uptime 信息
- 更健壮的错误处理
This commit is contained in:
2026-10-08 09:44:30 +08:00
parent af04d08458
commit 8e71996ab1

View File

@@ -868,12 +868,30 @@ async function testMbe() {
const healthUrl = isLocalhost ? `${mbeUrl.value}/health` : `${mbeUrl.value}/v1/health`
const resp = await fetch(healthUrl, { signal: AbortSignal.timeout(5000) })
if (!resp.ok) throw new Error(`HTTP ${resp.status}`)
const text = await resp.text()
if (text === 'OK') {
mbeStatus.value = 'online'
mbeInfo.value = { version: 'MarkBaseEngine', uptime: 0 }
// 兼容 JSON 和文本格式的响应
let isHealthy = false
const contentType = resp.headers.get('content-type') || ''
if (contentType.includes('application/json')) {
// JSON 格式响应
const json = await resp.json()
isHealthy = json.status === 'ok' || json.status === 'OK'
mbeInfo.value = {
version: json.version || 'MarkBaseEngine',
uptime: json.uptime || 0
}
} else {
throw new Error('Unexpected response: ' + text)
// 纯文本格式响应
const text = await resp.text()
isHealthy = text === 'OK' || text.includes('"status":"ok"')
mbeInfo.value = { version: 'MarkBaseEngine', uptime: 0 }
}
if (isHealthy) {
mbeStatus.value = 'online'
} else {
throw new Error('Unexpected response format')
}
} catch (e: any) {
mbeStatus.value = 'offline'