From: Jérôme Benoit Date: Fri, 30 Sep 2022 19:56:27 +0000 (+0200) Subject: Trivial code cleanups X-Git-Tag: v1.1.74~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=a307349b9b58052f14cc28b50b97c1113f744782;p=e-mobility-charging-stations-simulator.git Trivial code cleanups Signed-off-by: Jérôme Benoit --- 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 {