From 0d47c512d2862990dea3b548e98548e4a686a75e Mon Sep 17 00:00:00 2001 From: chenos Date: Wed, 13 Sep 2023 18:28:28 +0800 Subject: [PATCH] fix: parse websocket url (#2644) --- packages/core/client/src/application/WebSocketClient.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/core/client/src/application/WebSocketClient.ts b/packages/core/client/src/application/WebSocketClient.ts index cf92ccc4c..b730e5865 100644 --- a/packages/core/client/src/application/WebSocketClient.ts +++ b/packages/core/client/src/application/WebSocketClient.ts @@ -8,6 +8,10 @@ export const getWebSocketURL = () => { const subApp = getSubAppName(); const queryString = subApp ? `?__appName=${subApp}` : ''; if (process.env.WEBSOCKET_URL) { + const url = new URL(process.env.WEBSOCKET_URL); + if (url.hostname === 'localhost') { + return `${location.protocol === 'https:' ? 'wss' : 'ws'}://${location.hostname}:${url.port}/ws${queryString}`; + } return `${process.env.WEBSOCKET_URL}${queryString}`; } try {