Commit | Line | Data |
---|---|---|
8114d10e JB |
1 | import chalk from 'chalk'; |
2 | ||
eb3abc4f | 3 | import type { UIServerConfiguration } from '../../types/ConfigurationData'; |
fe94fce0 JB |
4 | import { ApplicationProtocol } from '../../types/UIProtocol'; |
5 | import Configuration from '../../utils/Configuration'; | |
6c1761d4 | 6 | import type { 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, | |
eb3abc4f | 18 | uiServerConfiguration?: UIServerConfiguration |
fe94fce0 | 19 | ): AbstractUIServer | null { |
eb3abc4f | 20 | if (UIServiceUtils.isLoopback(uiServerConfiguration.options?.host) === false) { |
d5bd1c00 JB |
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: | |
eb3abc4f | 29 | return new UIWebSocketServer(uiServerConfiguration ?? Configuration.getUIServer()); |
1f7fa4de | 30 | case ApplicationProtocol.HTTP: |
eb3abc4f | 31 | return new UIHttpServer(uiServerConfiguration ?? Configuration.getUIServer()); |
fe94fce0 JB |
32 | default: |
33 | return null; | |
34 | } | |
35 | } | |
36 | } |