diff --git a/build/serviceManager/Service.js b/build/serviceManager/Service.js index 4582c0b..16e8114 100644 --- a/build/serviceManager/Service.js +++ b/build/serviceManager/Service.js @@ -90,11 +90,13 @@ var Service = /** @class */ (function () { } }; Service.prototype.initConfiguration = function (data) { - this.log("Service " + data.name + " initialized"); this._CONFIG = data; - this.initialized = true; - if (data.isAuth) { - this.serviceManager.addServiceAuth(this); + if (!this.serviceManager.checkCluster(this)) { + this.initialized = true; + this.log("Service " + data.name + " initialized"); + if (data.isAuth) { + this.serviceManager.addServiceAuth(this); + } } }; Service.prototype.sendResponse = function (response) { diff --git a/build/serviceManager/index.js b/build/serviceManager/index.js index 34dce03..0bb8071 100644 --- a/build/serviceManager/index.js +++ b/build/serviceManager/index.js @@ -26,6 +26,26 @@ var ServiceManager = /** @class */ (function () { console.log("Service", service.name, "is the authService"); this.authSerivce = service; }; + ServiceManager.prototype.addService = function (socket) { + this.services.push(new Service_1.default(socket, this)); + }; + ServiceManager.prototype.checkCluster = function (currentService) { + var isCluster = false; + this.services.forEach(function (service) { + if (service === currentService) + return; + if (service.config && currentService.config) { + if (currentService.config.name === service.name) { + isCluster = true; + } + } + }); + if (isCluster) { + var serviceIndex = this.services.findIndex(function (service) { return service === currentService; }); + this.services.splice(serviceIndex, 1); + } + return isCluster; + }; ServiceManager.prototype.serviceClosed = function (serviceClosed) { var serviceIndex = this.services.findIndex(function (service) { return service === serviceClosed; }); if (this.authSerivce === this.services[serviceIndex]) { @@ -100,9 +120,6 @@ var ServiceManager = /** @class */ (function () { res.sendStatus(status); }); }; - ServiceManager.prototype.addService = function (socket) { - this.services.push(new Service_1.default(socket, this)); - }; return ServiceManager; }()); exports.default = ServiceManager; diff --git a/build/test.js b/build/test.js deleted file mode 100644 index 3ab8ec3..0000000 --- a/build/test.js +++ /dev/null @@ -1,3 +0,0 @@ -"use strict"; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.default = { hello: "world" }; diff --git a/serviceManager/Service.ts b/serviceManager/Service.ts index 4f3703b..d9f4905 100644 --- a/serviceManager/Service.ts +++ b/serviceManager/Service.ts @@ -75,11 +75,13 @@ export default class Service { } private initConfiguration(data: Config) { - this.log("Service " + data.name + " initialized"); this._CONFIG = data; - this.initialized = true; - if (data.isAuth) { - this.serviceManager.addServiceAuth(this); + if(!this.serviceManager.checkCluster(this)) { + this.initialized = true; + this.log("Service " + data.name + " initialized"); + if (data.isAuth) { + this.serviceManager.addServiceAuth(this); + } } } private sendResponse(response: any) { diff --git a/serviceManager/index.ts b/serviceManager/index.ts index 5ff5c86..ce1b2f1 100644 --- a/serviceManager/index.ts +++ b/serviceManager/index.ts @@ -17,6 +17,28 @@ export default class ServiceManager { this.authSerivce = service; } + private addService(socket: net.Socket) { + this.services.push(new Service(socket, this)); + } + + public checkCluster(currentService: Service) { + let isCluster = false; + this.services.forEach((service:Service) => { + if (service === currentService) return; + if (service.config && currentService.config) { + if (currentService.config.name === service.name) { + isCluster = true; + } + } + }); + + if (isCluster) { + const serviceIndex = this.services.findIndex((service: Service) => service === currentService); + this.services.splice(serviceIndex, 1); + } + return isCluster; + } + public serviceClosed(serviceClosed: Service) { const serviceIndex = this.services.findIndex((service: Service) => service === serviceClosed); if (this.authSerivce === this.services[serviceIndex]) { this.authSerivce = null; } @@ -80,8 +102,4 @@ export default class ServiceManager { res.sendStatus(status); }); } - - private addService(socket: net.Socket) { - this.services.push(new Service(socket, this)); - } }