UI Server: Add support for cloud foundry deployment
authorJérôme Benoit <jerome.benoit@sap.com>
Tue, 4 Oct 2022 19:29:50 +0000 (21:29 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Tue, 4 Oct 2022 19:29:50 +0000 (21:29 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
manifest-cf-template.yml
src/assets/config-template.json
src/utils/Configuration.ts

index f817d29f7ecdfc658591de4f1af544793b872c6e..3b9d4d7d8053cfb2bc2f0eb47da5d38db204123f 100644 (file)
@@ -5,7 +5,9 @@ applications:
     instances: 1
     buildpacks:
       - https://github.com/cloudfoundry/nodejs-buildpack
-    no-route: true
+    # no-route: true
+    routes:
+      - route: e-mobility-charging-stations-simulator.cfapps.sap.hana.ondemand.com
     health-check-type: process
     health-check-invocation-timeout: 10
     command: node -r source-map-support/register dist/start.cjs
index 51def2914a4144ecd8e3da819aceecd7c2be0d0e..9ad01aa1acc89c8cfa4e7f660d6f24454af2ee72 100644 (file)
     "enabled": true,
     "type": "jsonfile"
   },
+  "uiServer": {
+    "enabled": false,
+    "type": "ws",
+    "authentication": {
+      "enabled": true,
+      "type": "basic-auth",
+      "username": "admin",
+      "password": "admin"
+    }
+  },
   "stationTemplateUrls": [
     {
       "file": "siemens.station-template.json",
index c90c214d91b829ef1d558d02fc227e06a9abd706..86763f988ae96c52a97f8b7c7b194f075fbda4ae 100644 (file)
@@ -59,7 +59,7 @@ export default class Configuration {
       );
     }
     let uiServerConfiguration: UIServerConfiguration = {
-      enabled: true,
+      enabled: false,
       type: ApplicationProtocol.WS,
       options: {
         host: Constants.DEFAULT_UI_WEBSOCKET_SERVER_HOST,
@@ -72,6 +72,10 @@ export default class Configuration {
         Configuration.getConfig().uiServer
       );
     }
+    if (Configuration.isCFEnvironment() === true) {
+      delete uiServerConfiguration.options.host;
+      uiServerConfiguration.options.port = parseInt(process.env.PORT);
+    }
     return uiServerConfiguration;
   }
 
@@ -373,6 +377,10 @@ export default class Configuration {
     }
   }
 
+  private static isCFEnvironment(): boolean {
+    return process.env.VCAP_APPLICATION !== undefined;
+  }
+
   private static getDefaultPerformanceStorageUri(storageType: StorageType) {
     const SQLiteFileName = `${Constants.DEFAULT_PERFORMANCE_RECORDS_DB_NAME}.db`;
     switch (storageType) {
@@ -395,6 +403,14 @@ export default class Configuration {
     return item && typeof item === 'object' && Array.isArray(item) === false;
   }
 
+  private static objectHasOwnProperty(object: unknown, property: string): boolean {
+    return Object.prototype.hasOwnProperty.call(object, property) as boolean;
+  }
+
+  private static isUndefined(obj: unknown): boolean {
+    return typeof obj === 'undefined';
+  }
+
   private static deepMerge(target: object, ...sources: object[]): object {
     if (!sources.length) {
       return target;
@@ -418,14 +434,6 @@ export default class Configuration {
     return Configuration.deepMerge(target, ...sources);
   }
 
-  private static objectHasOwnProperty(object: unknown, property: string): boolean {
-    return Object.prototype.hasOwnProperty.call(object, property) as boolean;
-  }
-
-  private static isUndefined(obj: unknown): boolean {
-    return typeof obj === 'undefined';
-  }
-
   private static handleFileException(
     logPrefix: string,
     fileType: FileType,