@samveys/health
From packages/health/README.md in the framework repository.
Liveness and readiness endpoints for load balancers and orchestrators.
GET /health/liveanswers200 { "status": "ok" }while the process runs.GET /health/readyruns every check and answers200when all pass,503when 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
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
| Option | Default | Meaning |
|---|---|---|
path | /health | Prefix of the two endpoints |
checks | {} | Named checks: (signal) => Promise<{ ok, message? }> |
timeout | 2000 | Milliseconds per check; a slower check fails |
Other plugins add checks through the core extension point extend.healthCheck({ name, run }) in their boot().
Response
{ "status": "unavailable", "checks": { "database": { "ok": true }, "upstream": { "ok": false, "message": "timed out" } } }