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 }