From: Jérôme Benoit Date: Tue, 4 Oct 2022 19:29:50 +0000 (+0200) Subject: UI Server: Add support for cloud foundry deployment X-Git-Tag: v1.1.76~12 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=b803eefaa2cf9234da177d7058817baa8e99c841;p=e-mobility-charging-stations-simulator.git UI Server: Add support for cloud foundry deployment Signed-off-by: Jérôme Benoit --- 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,