Commit | Line | Data |
---|---|---|
8114d10e JB |
1 | import chalk from 'chalk'; |
2 | ||
4c3c0d59 JB |
3 | import type { AbstractUIServer } from './AbstractUIServer'; |
4 | import { UIHttpServer } from './UIHttpServer'; | |
5 | import { UIServerUtils } from './UIServerUtils'; | |
6 | import { UIWebSocketServer } from './UIWebSocketServer'; | |
864e5f8d | 7 | import { ApplicationProtocol, type UIServerConfiguration } from '../../types'; |
fe94fce0 | 8 | |
268a74bb | 9 | export class UIServerFactory { |
fe94fce0 JB |
10 | private constructor() { |
11 | // This is intentional | |
12 | } | |
13 | ||
14 | public static getUIServerImplementation( | |
864e5f8d | 15 | uiServerConfiguration: UIServerConfiguration, |
fe94fce0 | 16 | ): AbstractUIServer | null { |
864e5f8d | 17 | if (UIServerUtils.isLoopback(uiServerConfiguration.options!.host!) === false) { |
d5bd1c00 | 18 | console.warn( |
9c5d9fa4 | 19 | chalk.yellow( |
5edd8ba0 JB |
20 | 'Loopback address not detected in UI server configuration. This is not recommended.', |
21 | ), | |
d5bd1c00 JB |
22 | ); |
23 | } | |
864e5f8d | 24 | switch (uiServerConfiguration.type) { |
fe94fce0 | 25 | case ApplicationProtocol.WS: |
864e5f8d | 26 | return new UIWebSocketServer(uiServerConfiguration); |
1f7fa4de | 27 | case ApplicationProtocol.HTTP: |
864e5f8d | 28 | return new UIHttpServer(uiServerConfiguration); |
fe94fce0 JB |
29 | default: |
30 | return null; | |
31 | } | |
32 | } | |
33 | } |