Refine TS and linter configuration
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / UIServerFactory.ts
1 import chalk from 'chalk';
2
3 import type { ServerOptions } from '../../types/ConfigurationData';
4 import { ApplicationProtocol } from '../../types/UIProtocol';
5 import Configuration from '../../utils/Configuration';
6 import type { AbstractUIServer } from './AbstractUIServer';
7 import { UIServiceUtils } from './ui-services/UIServiceUtils';
8 import UIHttpServer from './UIHttpServer';
9 import UIWebSocketServer from './UIWebSocketServer';
10
11 export default class UIServerFactory {
12 private constructor() {
13 // This is intentional
14 }
15
16 public static getUIServerImplementation(
17 applicationProtocol: ApplicationProtocol,
18 options?: ServerOptions
19 ): AbstractUIServer | null {
20 if (!UIServiceUtils.isLoopback(options?.host)) {
21 console.warn(
22 chalk.magenta(
23 'Loopback address not detected in UI server configuration. This is not recommended.'
24 )
25 );
26 }
27 switch (applicationProtocol) {
28 case ApplicationProtocol.WS:
29 return new UIWebSocketServer(options ?? Configuration.getUIServer().options);
30 case ApplicationProtocol.HTTP:
31 return new UIHttpServer(options ?? Configuration.getUIServer().options);
32 default:
33 return null;
34 }
35 }
36 }