refactor: cleanup date handling
[e-mobility-charging-stations-simulator.git] / src / charging-station / ui-server / UIServerFactory.ts
index bbbb66b9c2fd67b01e2deb604345ae95314a7b36..c4006b0396d96c8d5ad50e902bfedf8ea2743c65 100644 (file)
@@ -1,34 +1,31 @@
 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 { UIHttpServer } from './UIHttpServer';
+import { UIServerUtils } from './UIServerUtils';
+import { UIWebSocketServer } from './UIWebSocketServer';
+import { ApplicationProtocol, type UIServerConfiguration } from '../../types';
 
-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(
-          'Loopback address not detected in UI server configuration. This is not recommended.'
-        )
+        chalk.yellow(
+          'Loopback address not detected in UI server configuration. This is not recommended.',
+        ),
       );
     }
-    switch (applicationProtocol) {
+    switch (uiServerConfiguration.type) {
       case ApplicationProtocol.WS:
-        return new UIWebSocketServer(options ?? Configuration.getUIServer().options);
+        return new UIWebSocketServer(uiServerConfiguration);
       case ApplicationProtocol.HTTP:
-        return new UIHttpServer(options ?? Configuration.getUIServer().options);
+        return new UIHttpServer(uiServerConfiguration);
       default:
         return null;
     }