@setu-ts/health-plugin — health checks and readiness probes
Add it: setu add health adds the dependency and inserts HealthPlugin() in recognized
scaffolds (already registered in REST projects). It provides CAPABILITIES.HEALTH
(IHealthService).
Probe an upstream dependency
Replace the existing registration in setu.config.ts:
import { createHttpIndicator, HealthPlugin } from "@setu-ts/health-plugin";
app.register(HealthPlugin({
indicators: [createHttpIndicator("billing", { url: "https://billing.example.com/health" })],
indicatorTimeoutMs: 3000,
}));
Read a complete health report
import { CAPABILITIES } from "@setu-ts/common";
import type { IHealthService } from "@setu-ts/common";
const health = ctx.services.get<IHealthService>(CAPABILITIES.HEALTH);
const report = await health.checkReady();
Behaviour the types do not show
- Default routes are
/health,/live,/ready./healthis503only for down,/readyis200only when every selected indicator is up, and/livealways responds200. checkLiveruns only the built-in self indicator;checkReadyexcludes it.checkruns all.detailsdefaults tofalse: HTTP checks expose only status, while programmatic reports always include indicator data and measured latency.- Indicators run concurrently, but report checks retain registration order. Duplicate names throw.
indicatorTimeoutMsdefaults to5000milliseconds. A timed-out or rejecting callback yields down with a fixed reason rather than serializing its thrown error.- Indicator factories in
indicatorsrun at initialization after all plugins register, so they can resolve later capabilities.createHttpIndicatoraccepts HTTP 2xx and 3xx as up.
Other options
endpointsreplaces the default path object; omitted keys skip their routes.createHttpIndicatoralso takestimeoutMsand an injectedfetcher.diagnosticswithenabled: trueand indicator aliases enables minimized observations underCAPABILITIES.HEALTH_DIAGNOSTICS(IHealthDiagnosticsSource);scheduledopts into polling.