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'; | |
a6080904 JB |
7 | import { |
8 | ApplicationProtocol, | |
9 | ApplicationProtocolVersion, | |
10 | type UIServerConfiguration, | |
11 | } from '../../types'; | |
12 | import { isUndefined } from '../../utils'; | |
fe94fce0 | 13 | |
268a74bb | 14 | export class UIServerFactory { |
fe94fce0 JB |
15 | private constructor() { |
16 | // This is intentional | |
17 | } | |
18 | ||
19 | public static getUIServerImplementation( | |
864e5f8d | 20 | uiServerConfiguration: UIServerConfiguration, |
fe94fce0 | 21 | ): AbstractUIServer | null { |
864e5f8d | 22 | if (UIServerUtils.isLoopback(uiServerConfiguration.options!.host!) === false) { |
d5bd1c00 | 23 | console.warn( |
9c5d9fa4 | 24 | chalk.yellow( |
5edd8ba0 JB |
25 | 'Loopback address not detected in UI server configuration. This is not recommended.', |
26 | ), | |
d5bd1c00 JB |
27 | ); |
28 | } | |
a6080904 JB |
29 | uiServerConfiguration = { |
30 | ...(uiServerConfiguration.type === ApplicationProtocol.HTTP && | |
31 | isUndefined(uiServerConfiguration.version) && { | |
32 | version: ApplicationProtocolVersion.VERSION_11, | |
33 | }), | |
34 | ...uiServerConfiguration, | |
35 | }; | |
864e5f8d | 36 | switch (uiServerConfiguration.type) { |
fe94fce0 | 37 | case ApplicationProtocol.WS: |
864e5f8d | 38 | return new UIWebSocketServer(uiServerConfiguration); |
1f7fa4de | 39 | case ApplicationProtocol.HTTP: |
864e5f8d | 40 | return new UIHttpServer(uiServerConfiguration); |
fe94fce0 JB |
41 | default: |
42 | return null; | |
43 | } | |
44 | } | |
45 | } |