@visulima/health-check
Version:
A library built to provide support for defining service health for node services. It allows you to register async health checks for your dependencies and the service itself, provides a health endpoint that exposes their status, and health metrics.
23 lines (20 loc) • 931 B
JavaScript
import { StatusCodes } from 'http-status-codes';
var __defProp = Object.defineProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
const healthcheck = /* @__PURE__ */ __name((healthCheck, sendHeader = true) => async (_, response) => {
const { healthy, report } = await healthCheck.getReport();
const payload = {
appName: process.env.APP_NAME ?? "unknown",
appVersion: process.env.APP_VERSION ?? "unknown",
message: healthy ? "Health check successful" : "Health check failed",
reports: report,
status: healthy ? "ok" : "error",
timestamp: (/* @__PURE__ */ new Date()).toISOString()
};
response.statusCode = healthy ? StatusCodes.OK : StatusCodes.SERVICE_UNAVAILABLE;
if (sendHeader) {
response.setHeader("Content-Type", "application/json");
}
response.end(JSON.stringify(payload, null, 2));
}, "default");
export { healthcheck as default };