X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2Fui-server%2FUIServerFactory.ts;h=c4006b0396d96c8d5ad50e902bfedf8ea2743c65;hb=142a66c9948adf165706107e1fcadf9f87bae559;hp=b0020b2e872e11dc6a59b0a5491f265203453a45;hpb=8114d10e3893e96bb725ce2fca9744429ee4b75b;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ui-server/UIServerFactory.ts b/src/charging-station/ui-server/UIServerFactory.ts index b0020b2e..c4006b03 100644 --- a/src/charging-station/ui-server/UIServerFactory.ts +++ b/src/charging-station/ui-server/UIServerFactory.ts @@ -1,31 +1,31 @@ import chalk from 'chalk'; -import { ServerOptions } from '../../types/ConfigurationData'; -import { ApplicationProtocol } from '../../types/UIProtocol'; -import Configuration from '../../utils/Configuration'; -import { AbstractUIServer } from './AbstractUIServer'; -import { UIServiceUtils } from './ui-services/UIServiceUtils'; -import UIWebSocketServer from './UIWebSocketServer'; +import type { AbstractUIServer } from './AbstractUIServer'; +import { UIHttpServer } from './UIHttpServer'; +import { UIServerUtils } from './UIServerUtils'; +import { UIWebSocketServer } from './UIWebSocketServer'; +import { ApplicationProtocol, type UIServerConfiguration } from '../../types'; -export default class UIServerFactory { +export class UIServerFactory { private constructor() { // This is intentional } public static getUIServerImplementation( - applicationProtocol: ApplicationProtocol, - options?: ServerOptions + uiServerConfiguration: UIServerConfiguration, ): AbstractUIServer | null { - if (!UIServiceUtils.isLoopback(options?.host)) { + if (UIServerUtils.isLoopback(uiServerConfiguration.options!.host!) === false) { console.warn( - chalk.magenta( - 'Loopback address not detected in UI server configuration. This is not recommended.' - ) + chalk.yellow( + 'Loopback address not detected in UI server configuration. This is not recommended.', + ), ); } - switch (applicationProtocol) { + switch (uiServerConfiguration.type) { case ApplicationProtocol.WS: - return new UIWebSocketServer(options ?? Configuration.getUIServer().options); + return new UIWebSocketServer(uiServerConfiguration); + case ApplicationProtocol.HTTP: + return new UIHttpServer(uiServerConfiguration); default: return null; }