From 8e71996ab13b69696a91ba0686a215768ae1b00b Mon Sep 17 00:00:00 2001 From: Momentry Studio Date: Thu, 8 Oct 2026 09:44:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20MarkBase=20Engine?= =?UTF-8?q?=20=E5=81=A5=E5=BA=B7=E6=A3=80=E6=9F=A5=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=B8=8D=E5=8C=B9=E9=85=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题: - MarkBase Engine 的 /health 端点返回 JSON 格式 {"status":"ok"} - testMbe 函数期望纯文本 "OK" - 导致状态被错误地设置为 offline 修复: - 使用 Content-Type 判断响应格式 - JSON 格式:解析并检查 status 字段 - 纯文本格式:检查是否为 "OK" 或包含 JSON 状态 - 兼容两种响应格式,确保状态正确 改进: - 从 JSON 响应中提取 version 和 uptime 信息 - 更健壮的错误处理 --- src/views/AdminView.vue | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/views/AdminView.vue b/src/views/AdminView.vue index 22c9b3e..af837dc 100644 --- a/src/views/AdminView.vue +++ b/src/views/AdminView.vue @@ -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'