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