X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Futils%2FConfiguration.ts;h=4fc46b059ffa9dfa1aa5ce4c99883e758eb12c68;hb=adbddcb44d65e7268f661deacc4291d6cf6f6663;hp=afc992f8e7841b35f44a49841ee1c63f452e5285;hpb=6c1761d470507ea23d186be61b94ca7375c5144a;p=e-mobility-charging-stations-simulator.git diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index afc992f8..4fc46b05 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -4,12 +4,13 @@ import { fileURLToPath } from 'url'; import chalk from 'chalk'; -import ConfigurationData, { - StationTemplateUrl, - StorageConfiguration, +import { + type ConfigurationData, + type StationTemplateUrl, + type StorageConfiguration, SupervisionUrlDistribution, - UIServerConfiguration, - WorkerConfiguration, + type UIServerConfiguration, + type WorkerConfiguration, } from '../types/ConfigurationData'; import type { EmptyObject } from '../types/EmptyObject'; import type { HandleErrorParams } from '../types/Error'; @@ -58,11 +59,11 @@ export default class Configuration { ); } let uiServerConfiguration: UIServerConfiguration = { - enabled: true, + enabled: false, type: ApplicationProtocol.WS, options: { - host: Constants.DEFAULT_UI_WEBSOCKET_SERVER_HOST, - port: Constants.DEFAULT_UI_WEBSOCKET_SERVER_PORT, + host: Constants.DEFAULT_UI_SERVER_HOST, + port: Constants.DEFAULT_UI_SERVER_PORT, }, }; if (Configuration.objectHasOwnProperty(Configuration.getConfig(), 'uiServer')) { @@ -71,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; } @@ -372,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) { @@ -394,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; @@ -417,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,