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'; |
1f7fa4de | 7 | import UIHttpServer from './UIHttpServer'; |
ed3d2808 | 8 | import { UIServerUtils } from './UIServerUtils'; |
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( | |
eb3abc4f | 17 | uiServerConfiguration?: UIServerConfiguration |
fe94fce0 | 18 | ): AbstractUIServer | null { |
ed3d2808 | 19 | if (UIServerUtils.isLoopback(uiServerConfiguration.options?.host) === false) { |
d5bd1c00 | 20 | console.warn( |
9c5d9fa4 | 21 | chalk.yellow( |
d5bd1c00 JB |
22 | 'Loopback address not detected in UI server configuration. This is not recommended.' |
23 | ) | |
24 | ); | |
25 | } | |
976d11ec | 26 | switch (uiServerConfiguration?.type ?? Configuration.getUIServer().type) { |
fe94fce0 | 27 | case ApplicationProtocol.WS: |
eb3abc4f | 28 | return new UIWebSocketServer(uiServerConfiguration ?? Configuration.getUIServer()); |
1f7fa4de | 29 | case ApplicationProtocol.HTTP: |
eb3abc4f | 30 | return new UIHttpServer(uiServerConfiguration ?? Configuration.getUIServer()); |
fe94fce0 JB |
31 | default: |
32 | return null; | |
33 | } | |
34 | } | |
35 | } |