From 662710925f570077ed9af59519912546f9bb8eaa Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 13 May 2022 14:06:32 +0200 Subject: [PATCH] Add deprecation warning for ui server configuration section renaming MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/ui-server/UIWebSocketServer.ts | 5 +++-- src/types/ConfigurationData.ts | 5 ++++- src/utils/Configuration.ts | 7 ++++++- 3 files changed, 13 insertions(+), 4 deletions(-) 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, -- 2.34.1