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