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