Commit | Line | Data |
---|---|---|
8114d10e JB |
1 | import chalk from 'chalk'; |
2 | ||
3 | import { ServerOptions } from '../../types/ConfigurationData'; | |
fe94fce0 JB |
4 | import { ApplicationProtocol } from '../../types/UIProtocol'; |
5 | import Configuration from '../../utils/Configuration'; | |
8114d10e | 6 | import { AbstractUIServer } from './AbstractUIServer'; |
d5bd1c00 | 7 | import { UIServiceUtils } from './ui-services/UIServiceUtils'; |
1f7fa4de | 8 | import UIHttpServer from './UIHttpServer'; |
fe94fce0 JB |
9 | import UIWebSocketServer from './UIWebSocketServer'; |
10 | ||
11 | export default class UIServerFactory { | |
12 | private constructor() { | |
13 | // This is intentional | |
14 | } | |
15 | ||
16 | public static getUIServerImplementation( | |
17 | applicationProtocol: ApplicationProtocol, | |
b153c0fd | 18 | options?: ServerOptions |
fe94fce0 | 19 | ): AbstractUIServer | null { |
d5bd1c00 JB |
20 | if (!UIServiceUtils.isLoopback(options?.host)) { |
21 | console.warn( | |
22 | chalk.magenta( | |
23 | 'Loopback address not detected in UI server configuration. This is not recommended.' | |
24 | ) | |
25 | ); | |
26 | } | |
fe94fce0 JB |
27 | switch (applicationProtocol) { |
28 | case ApplicationProtocol.WS: | |
b153c0fd | 29 | return new UIWebSocketServer(options ?? Configuration.getUIServer().options); |
1f7fa4de JB |
30 | case ApplicationProtocol.HTTP: |
31 | return new UIHttpServer(options ?? Configuration.getUIServer().options); | |
fe94fce0 JB |
32 | default: |
33 | return null; | |
34 | } | |
35 | } | |
36 | } |