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