build(deps-dev): apply updates
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / UIServerFactory.ts
CommitLineData
8114d10e
JB
1import chalk from 'chalk';
2
4c3c0d59
JB
3import type { AbstractUIServer } from './AbstractUIServer';
4import { UIHttpServer } from './UIHttpServer';
5import { UIServerUtils } from './UIServerUtils';
6import { UIWebSocketServer } from './UIWebSocketServer';
268a74bb 7import { ApplicationProtocol, type UIServerConfiguration } from '../../types';
60a74391 8import { Configuration } from '../../utils';
fe94fce0 9
268a74bb 10export class UIServerFactory {
fe94fce0
JB
11 private constructor() {
12 // This is intentional
13 }
14
15 public static getUIServerImplementation(
5edd8ba0 16 uiServerConfiguration?: UIServerConfiguration,
fe94fce0 17 ): AbstractUIServer | null {
e1d9a0f4 18 if (UIServerUtils.isLoopback(uiServerConfiguration!.options!.host!) === false) {
d5bd1c00 19 console.warn(
9c5d9fa4 20 chalk.yellow(
5edd8ba0
JB
21 'Loopback address not detected in UI server configuration. This is not recommended.',
22 ),
d5bd1c00
JB
23 );
24 }
976d11ec 25 switch (uiServerConfiguration?.type ?? Configuration.getUIServer().type) {
fe94fce0 26 case ApplicationProtocol.WS:
eb3abc4f 27 return new UIWebSocketServer(uiServerConfiguration ?? Configuration.getUIServer());
1f7fa4de 28 case ApplicationProtocol.HTTP:
eb3abc4f 29 return new UIHttpServer(uiServerConfiguration ?? Configuration.getUIServer());
fe94fce0
JB
30 default:
31 return null;
32 }
33 }
34}