fix: ensure daily recurring charging profiles are adjusted on a day
[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';
864e5f8d 7import { ApplicationProtocol, type UIServerConfiguration } from '../../types';
fe94fce0 8
268a74bb 9export class UIServerFactory {
fe94fce0
JB
10 private constructor() {
11 // This is intentional
12 }
13
14 public static getUIServerImplementation(
864e5f8d 15 uiServerConfiguration: UIServerConfiguration,
fe94fce0 16 ): AbstractUIServer | null {
864e5f8d 17 if (UIServerUtils.isLoopback(uiServerConfiguration.options!.host!) === false) {
d5bd1c00 18 console.warn(
9c5d9fa4 19 chalk.yellow(
5edd8ba0
JB
20 'Loopback address not detected in UI server configuration. This is not recommended.',
21 ),
d5bd1c00
JB
22 );
23 }
864e5f8d 24 switch (uiServerConfiguration.type) {
fe94fce0 25 case ApplicationProtocol.WS:
864e5f8d 26 return new UIWebSocketServer(uiServerConfiguration);
1f7fa4de 27 case ApplicationProtocol.HTTP:
864e5f8d 28 return new UIHttpServer(uiServerConfiguration);
fe94fce0
JB
29 default:
30 return null;
31 }
32 }
33}