UNPKG

@mdf.js/service-registry

Version:

MMS - API - Service Registry

52 lines 2.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Router = void 0; const tslib_1 = require("tslib"); /** * Copyright 2024 Mytra Control S.L. All rights reserved. * * Use of this source code is governed by an MIT-style license that can be found in the LICENSE file * or at https://opensource.org/licenses/MIT. */ const express_1 = tslib_1.__importDefault(require("express")); const types_1 = require("../types"); const metrics_controller_1 = require("./metrics.controller"); const metrics_model_1 = require("./metrics.model"); const metrics_service_1 = require("./metrics.service"); const metrics_validator_1 = require("./metrics.validator"); const PREFIX_PATH = `/${types_1.METRICS_SERVICE_NAME}`; /** Router class */ class Router { /** * Create a new instance of the Router class * @param aggregator - Aggregator used by this component * @param isCluster - indicates that the instance of this metrics service is running in a cluster * @param path - prefix path for all the routes */ constructor(aggregator, isCluster = false, path = PREFIX_PATH) { this.aggregator = aggregator; this.path = path; this._model = new metrics_model_1.Model(this.aggregator); this._service = new metrics_service_1.Service(this._model); this._controller = new metrics_controller_1.Controller(this._service, isCluster); this._validator = new metrics_validator_1.Validator(); this._router = this.buildRoutes(this.path); } /** * Perform the instantiation of the routes in an express router * @param path - prefix path for all the routers */ buildRoutes(path) { const router = express_1.default.Router(); router .route(path) .get(this._validator.metrics.bind(this._validator), this._controller.metrics.bind(this._controller)); return router; } /** Express router for health REST API component*/ get router() { return this._router; } } exports.Router = Router; //# sourceMappingURL=metrics.router.js.map