文档中心

探索 DWeb 框架的无限可能,构建下一代高性能 Web 应用

health - 健康检查

health 中间件提供应用健康检查端点,用于监控应用状态。

基本使用

Code
import { health } from '@dreamer/dweb';

server.use(health({
  path: '/health',
  checks: {
    database: async () => {
      // 检查数据库连接
      return { status: 'ok' };
    },
  },
}));

配置选项

可选参数

  • path - 健康检查路径(默认 '/health')
  • readyPath - 就绪检查路径(默认 '/health/ready')
  • livePath - 存活检查路径(默认 '/health/live')
  • healthCheck - 自定义健康检查函数,返回 Promise,包含 status('ok' | 'error')、message 和 details
  • readyCheck - 自定义就绪检查函数,返回 Promise,包含 status('ready' | 'not-ready')、message 和 details
  • liveCheck - 自定义存活检查函数,返回 Promise,包含 status('alive' | 'dead')、message 和 details