Trivial code cleanups
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 30 Sep 2022 19:56:27 +0000 (21:56 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 30 Sep 2022 19:56:27 +0000 (21:56 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/Bootstrap.ts
src/charging-station/ui-server/AbstractUIServer.ts
src/charging-station/ui-server/UIHttpServer.ts
src/charging-station/ui-server/UIWebSocketServer.ts

index cfb4eed6b309721fc5055998ca71526bc3366cb6..17fe96095a6c197f90d3edf38b2033212424c723 100644 (file)
@@ -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(
index d8ef6340296b5b2ddefa4dbd471529e197a72f40..596ddb598d78bfb10dca5c076b395e059289ba87 100644 (file)
@@ -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));
index 37c579dc56a552dc26dbd57ae515378820e9e2d9..4b911efd96b2d97aaf338fb4dd618e23064a934d 100644 (file)
@@ -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
index f8f836b1073b98b0f861145cefa441ba71192f89..83d074cf3414edd9afd1d53b3b6abe64adfda735 100644 (file)
@@ -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 {