UNPKG

@cran/gql.koa

Version:

Cran/GraphQL Koa Server

28 lines (27 loc) 764 B
"use strict"; /* eslint-disable require-atomic-updates */ Object.defineProperty(exports, "__esModule", { value: true }); exports.health = void 0; async function defaultHealth(_) { return true; } 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; }; } exports.health = health;