@cran/gql.koa
Version:
Cran/GraphQL Koa Server
24 lines (23 loc) • 644 B
JavaScript
/* eslint-disable require-atomic-updates */
async function defaultHealth(_) {
return true;
}
export function health(getHealth = defaultHealth) {
return async function healthMiddleware(ctx) {
ctx.set("Content-Type", "application/health+json");
let healthy = true;
try {
healthy = await getHealth(ctx);
}
catch {
healthy = false;
}
if ("boolean" === typeof healthy) {
healthy = { status: healthy ? "pass" : "fail", };
}
if ("fail" === healthy.status) {
ctx.status = 503;
}
ctx.body = healthy;
};
}