@samveys/health

Versi
1.0.35 Nov 2026
Pasang
pnpm add @samveys/health

Dari packages/health/README.md di repository framework.

Halaman ini belum diterjemahkan. Kamu sedang membaca versi bahasa Inggris.

Liveness and readiness endpoints for load balancers and orchestrators.

  • GET /health/live answers 200 { "status": "ok" } while the process runs.
  • GET /health/ready runs every check and answers 200 when all pass, 503 when one fails or times out.
  • Readiness flips to 503 (shutting_down) as soon as the app starts terminating, before the HTTP drain, so traffic moves away first.

Use it

ts
import { createApp } from '@samveys/core'
import { http } from '@samveys/http'
import { health } from '@samveys/health'

export const app = createApp({
  name: 'billing',
  plugins: [
    http(),
    health({
      checks: {
        // A check gets an AbortSignal and must finish within `timeout` (default 2000 ms).
        upstream: async () => ({ ok: true }),
      },
    }),
  ],
})

With @samveys/database registered, a database check (select 1) is added automatically.

Options

OptionDefaultMeaning
path/healthPrefix of the two endpoints
checks{}Named checks: (signal) => Promise<{ ok, message? }>
timeout2000Milliseconds per check; a slower check fails

Other plugins add checks through the core extension point extend.healthCheck({ name, run }) in their boot().

Response

json
{ "status": "unavailable", "checks": { "database": { "ok": true }, "upstream": { "ok": false, "message": "timed out" } } }