From b803eefaa2cf9234da177d7058817baa8e99c841 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 4 Oct 2022 21:29:50 +0200 Subject: [PATCH] UI Server: Add support for cloud foundry deployment MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- manifest-cf-template.yml | 4 +++- src/assets/config-template.json | 10 ++++++++++ src/utils/Configuration.ts | 26 +++++++++++++++++--------- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/manifest-cf-template.yml b/manifest-cf-template.yml index f817d29f..3b9d4d7d 100644 --- a/manifest-cf-template.yml +++ b/manifest-cf-template.yml @@ -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 diff --git a/src/assets/config-template.json b/src/assets/config-template.json index 51def291..9ad01aa1 100644 --- a/src/assets/config-template.json +++ b/src/assets/config-template.json @@ -11,6 +11,16 @@ "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", diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index c90c214d..86763f98 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -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, -- 2.34.1