feat: add support for evses in all identified code paths
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / UIServerFactory.ts
index bbbb66b9c2fd67b01e2deb604345ae95314a7b36..905ce66d5325fc7bca9424d6f313de5cec089588 100644 (file)
@@ -1,34 +1,29 @@
 import chalk from 'chalk';
 
-import type { ServerOptions } from '../../types/ConfigurationData';
-import { ApplicationProtocol } from '../../types/UIProtocol';
-import Configuration from '../../utils/Configuration';
-import type { AbstractUIServer } from './AbstractUIServer';
-import { UIServiceUtils } from './ui-services/UIServiceUtils';
-import UIHttpServer from './UIHttpServer';
-import UIWebSocketServer from './UIWebSocketServer';
+import { ApplicationProtocol, type UIServerConfiguration } from '../../types';
+import { Configuration } from '../../utils';
+import { type AbstractUIServer, UIHttpServer, UIServerUtils, UIWebSocketServer } from '../internal';
 
-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(
+        chalk.yellow(
           'Loopback address not detected in UI server configuration. This is not recommended.'
         )
       );
     }
-    switch (applicationProtocol) {
+    switch (uiServerConfiguration?.type ?? Configuration.getUIServer().type) {
       case ApplicationProtocol.WS:
-        return new UIWebSocketServer(options ?? Configuration.getUIServer().options);
+        return new UIWebSocketServer(uiServerConfiguration ?? Configuration.getUIServer());
       case ApplicationProtocol.HTTP:
-        return new UIHttpServer(options ?? Configuration.getUIServer().options);
+        return new UIHttpServer(uiServerConfiguration ?? Configuration.getUIServer());
       default:
         return null;
     }