-import { AbstractUIServer } from './AbstractUIServer';
-import { ApplicationProtocol } from '../../types/UIProtocol';
-import Configuration from '../../utils/Configuration';
-import { ServerOptions } from '../../types/ConfigurationData';
-import UIWebSocketServer from './UIWebSocketServer';
+import chalk from 'chalk';
-export default class UIServerFactory {
+import type { AbstractUIServer } from './AbstractUIServer';
+import { UIHttpServer } from './UIHttpServer';
+import { UIServerUtils } from './UIServerUtils';
+import { UIWebSocketServer } from './UIWebSocketServer';
+import { ApplicationProtocol, type UIServerConfiguration } from '../../types';
+
+export class UIServerFactory {
private constructor() {
// This is intentional
}
public static getUIServerImplementation(
- applicationProtocol: ApplicationProtocol,
- options?: ServerOptions
+ uiServerConfiguration: UIServerConfiguration,
): AbstractUIServer | null {
- switch (applicationProtocol) {
+ if (UIServerUtils.isLoopback(uiServerConfiguration.options!.host!) === false) {
+ console.warn(
+ chalk.yellow(
+ 'Loopback address not detected in UI server configuration. This is not recommended.',
+ ),
+ );
+ }
+ switch (uiServerConfiguration.type) {
case ApplicationProtocol.WS:
- return new UIWebSocketServer(options ?? Configuration.getUIServer().options);
+ return new UIWebSocketServer(uiServerConfiguration);
+ case ApplicationProtocol.HTTP:
+ return new UIHttpServer(uiServerConfiguration);
default:
return null;
}