@mdf.js/service-registry
Version:
MMS - API - Service Registry
47 lines • 1.8 kB
JavaScript
;
/**
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.Router = void 0;
const tslib_1 = require("tslib");
const express_1 = tslib_1.__importDefault(require("express"));
const types_1 = require("../types");
const registry_controller_1 = require("./registry.controller");
const registry_model_1 = require("./registry.model");
const registry_service_1 = require("./registry.service");
const PREFIX_PATH = `/${types_1.REGISTER_SERVICE_NAME}`;
/** Router class */
class Router {
/**
* Create a new instance of the Router class
* @param aggregator - Aggregator used by this component
* @param path - prefix path for all the routes
*/
constructor(aggregator, path = PREFIX_PATH) {
this.aggregator = aggregator;
this.path = path;
this._model = new registry_model_1.Model(this.aggregator);
this._service = new registry_service_1.Service(this._model);
this._controller = new registry_controller_1.Controller(this._service);
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(registersPath) {
const router = express_1.default.Router();
router.route(registersPath).get(this._controller.errors.bind(this._controller));
return router;
}
/** Express router for health REST API component*/
get router() {
return this._router;
}
}
exports.Router = Router;
//# sourceMappingURL=registry.router.js.map