From: Jérôme Benoit Date: Fri, 13 May 2022 12:06:32 +0000 (+0200) Subject: Add deprecation warning for ui server configuration section renaming X-Git-Tag: v1.1.60~12 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=662710925f570077ed9af59519912546f9bb8eaa;p=e-mobility-charging-stations-simulator.git Add deprecation warning for ui server configuration section renaming Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/ui-server/UIWebSocketServer.ts b/src/charging-station/ui-server/UIWebSocketServer.ts index abc3ec67..2e03ebc2 100644 --- a/src/charging-station/ui-server/UIWebSocketServer.ts +++ b/src/charging-station/ui-server/UIWebSocketServer.ts @@ -1,9 +1,10 @@ import { Protocol, ProtocolVersion } from '../../types/UIProtocol'; -import WebSocket, { OPEN, Server, ServerOptions } from 'ws'; +import WebSocket, { OPEN, Server } from 'ws'; import AbstractUIService from './ui-services/AbstractUIService'; import Configuration from '../../utils/Configuration'; import { IncomingMessage } from 'http'; +import { ServerOptions } from '../../types/ConfigurationData'; import UIServiceFactory from './ui-services/UIServiceFactory'; import Utils from '../../utils/Utils'; import logger from '../../utils/Logger'; @@ -13,7 +14,7 @@ export default class UIWebSocketServer extends Server { private readonly uiServices: Map; public constructor(options?: ServerOptions, callback?: () => void) { - // Create the WebSocket Server + // Create the WebSocket server super(options ?? Configuration.getUIServer().options, callback); this.chargingStations = new Set(); this.uiServices = new Map(); diff --git a/src/types/ConfigurationData.ts b/src/types/ConfigurationData.ts index a7b22af6..93b0b75c 100644 --- a/src/types/ConfigurationData.ts +++ b/src/types/ConfigurationData.ts @@ -1,8 +1,11 @@ +import { ServerOptions as HttpServerOptions } from 'http'; import { StorageType } from './Storage'; import { ServerOptions as WSServerOptions } from 'ws'; import type { WorkerChoiceStrategy } from 'poolifier'; import { WorkerProcessType } from './Worker'; +export type ServerOptions = WSServerOptions & HttpServerOptions; + export enum SupervisionUrlDistribution { ROUND_ROBIN = 'round-robin', RANDOM = 'random', @@ -16,7 +19,7 @@ export interface StationTemplateUrl { export interface UIServerConfiguration { enabled?: boolean; - options?: WSServerOptions; + options?: ServerOptions; } export interface StorageConfiguration { diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 0b0bec77..491c377e 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -1,4 +1,5 @@ import ConfigurationData, { + ServerOptions, StationTemplateUrl, StorageConfiguration, SupervisionUrlDistribution, @@ -9,7 +10,6 @@ import Constants from './Constants'; import { EmptyObject } from '../types/EmptyObject'; import { FileType } from '../types/FileType'; import { HandleErrorParams } from '../types/Error'; -import { ServerOptions } from 'ws'; import { StorageType } from '../types/Storage'; import type { WorkerChoiceStrategy } from 'poolifier'; import WorkerConstants from '../worker/WorkerConstants'; @@ -46,6 +46,11 @@ export default class Configuration { } static getUIServer(): UIServerConfiguration { + if (Configuration.objectHasOwnProperty(Configuration.getConfig(), 'uiWebSocketServer')) { + console.error( + chalk`{green ${Configuration.logPrefix()}} {red Deprecated configuration section 'uiWebSocketServer' usage. Use 'uiServer' instead}` + ); + } let options: ServerOptions = { host: Constants.DEFAULT_UI_WEBSOCKET_SERVER_HOST, port: Constants.DEFAULT_UI_WEBSOCKET_SERVER_PORT,