From 4e7b02206fbe39adaf43a77fff765d8e95140ff1 Mon Sep 17 00:00:00 2001 From: huang <1724659546@qq.com> Date: Mon, 10 Nov 2025 23:26:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0api.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/health.js | 25 +++++++++++++++++++++++++ src/api/index.js | 2 ++ 2 files changed, 27 insertions(+) create mode 100644 src/api/health.js diff --git a/src/api/health.js b/src/api/health.js new file mode 100644 index 00000000..f938d77e --- /dev/null +++ b/src/api/health.js @@ -0,0 +1,25 @@ +import http from '../utils/http'; +import { Response } from '../enums'; + +// --- API Functions --- + +/** + * 检查服务进程是否运行正常,只要服务能响应就返回 200 OK。 + * @returns {Promise} + */ +export const getHealthz = () => { + return http.get('/healthz'); +}; + +/** + * 检查服务是否已准备好接收流量。当前实现为只要服务能响应即代表就绪。 + * @returns {Promise} + */ +export const getReadyz = () => { + return http.get('/readyz'); +}; + +export const HealthApi = { + getHealthz, + getReadyz, +}; diff --git a/src/api/index.js b/src/api/index.js index 94725c76..f73709e9 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -2,6 +2,7 @@ import { AreaControllerApi, DeviceApi } from './device.js'; import { PlanApi } from './plan.js'; import { UserApi } from './user.js'; import { AlarmApi } from './alarm.js'; // 导入告警API +import { HealthApi } from './health.js'; // 导入健康检查API import { DeviceTemplateApi } from './deviceTemplate.js'; // 导入设备模板API /** @@ -13,6 +14,7 @@ export class ApiClient { this.devices = DeviceApi; this.plans = PlanApi; this.users = UserApi; + this.health = HealthApi; // 添加健康检查API this.alarms = AlarmApi; // 添加告警API this.deviceTemplates = DeviceTemplateApi; // 添加设备模板API }