UNPKG

node-microsvc-lib

Version:
83 lines 3.5 kB
/** * Created by pedrosousabarreto@gmail.com on 15/Jan/2019. */ "use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HealthCheck = void 0; const express = __importStar(require("express")); const console_logger_1 = require("../../console_logger"); const my_path = "/_health_check"; class HealthCheck { constructor(configs, express_app, logger) { this._name = "HealthCheck"; this._configs = configs; this._express_app = express_app; if (!logger) this._logger = new console_logger_1.ConsoleLogger().create_child({ class: "HealthCheck" }); else this._logger = logger.create_child({ class: "HealthCheck" }); } get name() { return this._name; } ; init() { return __awaiter(this, void 0, void 0, function* () { this._logger.info("%s initialising...", this.name); yield this._inject_routes().catch((err) => { this._logger.error(err, this.name + " Error initializing"); return Promise.reject(err); }).then(() => { this._logger.info("%s initialised", this.name); return Promise.resolve(); }); }); } destroy() { return __awaiter(this, void 0, void 0, function* () { this._logger.info("%s - destroying...", this.name); }); } _inject_routes() { return __awaiter(this, void 0, void 0, function* () { this._logger.info("%s initialising routes...", this.name); let router = express.Router(); router.get(my_path, this._health_check_handler.bind(this)); this._express_app.use(this._configs.app_base_url, router); }); } _health_check_handler(req, res, next) { // TODO add overrideable custom handler res.status(200).json({ status: "ok" }); } } exports.HealthCheck = HealthCheck; //# sourceMappingURL=health_check.js.map