From a307349b9b58052f14cc28b50b97c1113f744782 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 30 Sep 2022 21:56:27 +0200 Subject: [PATCH] Trivial code cleanups MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Bootstrap.ts | 10 ++++++---- src/charging-station/ui-server/AbstractUIServer.ts | 6 ++++++ src/charging-station/ui-server/UIHttpServer.ts | 4 +--- src/charging-station/ui-server/UIWebSocketServer.ts | 4 +--- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index cfb4eed6..17fe9609 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -30,8 +30,10 @@ import UIServerFactory from './ui-server/UIServerFactory'; const moduleName = 'Bootstrap'; -const missingChargingStationsConfigurationExitCode = 1; -const noChargingStationTemplatesExitCode = 2; +enum exitCodes { + missingChargingStationsConfiguration = 1, + noChargingStationTemplates = 2, +} export class Bootstrap { private static instance: Bootstrap | null = null; @@ -107,13 +109,13 @@ export class Bootstrap { console.warn( chalk.yellow("'stationTemplateUrls' not defined or empty in configuration, exiting") ); - process.exit(missingChargingStationsConfigurationExitCode); + process.exit(exitCodes.missingChargingStationsConfiguration); } if (this.numberOfChargingStations === 0) { console.warn( chalk.yellow('No charging station template enabled in configuration, exiting') ); - process.exit(noChargingStationTemplatesExitCode); + process.exit(exitCodes.noChargingStationTemplates); } else { console.info( chalk.green( diff --git a/src/charging-station/ui-server/AbstractUIServer.ts b/src/charging-station/ui-server/AbstractUIServer.ts index d8ef6340..596ddb59 100644 --- a/src/charging-station/ui-server/AbstractUIServer.ts +++ b/src/charging-station/ui-server/AbstractUIServer.ts @@ -45,6 +45,12 @@ export abstract class AbstractUIServer { this.chargingStations.clear(); } + protected startHttpServer(): void { + if (this.httpServer.listening === false) { + this.httpServer.listen(this.uiServerConfiguration.options); + } + } + protected registerProtocolVersionUIService(version: ProtocolVersion): void { if (this.uiServices.has(version) === false) { this.uiServices.set(version, UIServiceFactory.getUIServiceImplementation(version, this)); diff --git a/src/charging-station/ui-server/UIHttpServer.ts b/src/charging-station/ui-server/UIHttpServer.ts index 37c579dc..4b911efd 100644 --- a/src/charging-station/ui-server/UIHttpServer.ts +++ b/src/charging-station/ui-server/UIHttpServer.ts @@ -27,9 +27,7 @@ export default class UIHttpServer extends AbstractUIServer { public start(): void { this.httpServer.on('request', this.requestListener.bind(this) as RequestListener); - if (this.httpServer.listening === false) { - this.httpServer.listen(this.uiServerConfiguration.options); - } + this.startHttpServer(); } // eslint-disable-next-line @typescript-eslint/no-unused-vars diff --git a/src/charging-station/ui-server/UIWebSocketServer.ts b/src/charging-station/ui-server/UIWebSocketServer.ts index f8f836b1..83d074cf 100644 --- a/src/charging-station/ui-server/UIWebSocketServer.ts +++ b/src/charging-station/ui-server/UIWebSocketServer.ts @@ -83,9 +83,7 @@ export default class UIWebSocketServer extends AbstractUIServer { }); } ); - if (this.httpServer.listening === false) { - this.httpServer.listen(this.uiServerConfiguration.options); - } + this.startHttpServer(); } public sendRequest(request: ProtocolRequest): void { -- 2.34.1