UNPKG

@backstage/backend-defaults

Version:

Backend defaults used by Backstage backend apps

49 lines (45 loc) 1.34 kB
'use strict'; var backendPluginApi = require('@backstage/backend-plugin-api'); class DefaultRootHealthService { #state = "init"; options; constructor(options) { this.options = options; options.lifecycle.addStartupHook(() => { this.#state = "up"; }); options.lifecycle.addBeforeShutdownHook(() => { this.#state = "down"; }); } async getLiveness() { return { status: 200, payload: { status: "ok" } }; } async getReadiness() { if (this.#state === "init") { return { status: 503, payload: { message: "Backend has not started yet", status: "error" } }; } if (this.#state === "down") { return { status: 503, payload: { message: "Backend is shuttting down", status: "error" } }; } return { status: 200, payload: { status: "ok" } }; } } const rootHealthServiceFactory = backendPluginApi.createServiceFactory({ service: backendPluginApi.coreServices.rootHealth, deps: { lifecycle: backendPluginApi.coreServices.rootLifecycle }, async factory({ lifecycle }) { return new DefaultRootHealthService({ lifecycle }); } }); exports.DefaultRootHealthService = DefaultRootHealthService; exports.rootHealthServiceFactory = rootHealthServiceFactory; //# sourceMappingURL=rootHealthServiceFactory.cjs.js.map