diff --git a/web/app/components/workflow/collaboration/core/websocket-manager.ts b/web/app/components/workflow/collaboration/core/websocket-manager.ts index b5d63c04d2..cbcc04fb1b 100644 --- a/web/app/components/workflow/collaboration/core/websocket-manager.ts +++ b/web/app/components/workflow/collaboration/core/websocket-manager.ts @@ -8,8 +8,14 @@ export class WebSocketClient { private config: WebSocketConfig constructor(config: WebSocketConfig = {}) { + const inferUrl = () => { + if (typeof window === 'undefined') + return 'ws://localhost:5001' + const scheme = window.location.protocol === 'https:' ? 'wss:' : 'ws:' + return `${scheme}//${window.location.host}` + } this.config = { - url: config.url || process.env.NEXT_PUBLIC_SOCKET_URL || 'ws://localhost:5001', + url: config.url || process.env.NEXT_PUBLIC_SOCKET_URL || inferUrl(), transports: config.transports || ['websocket'], withCredentials: config.withCredentials !== false, ...config,