From ce2bfbab7e0507fb296f5347ba24ba8e650f631f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=9C=A8=E8=99=8E?= Date: Sun, 17 Dec 2023 10:58:00 +0800 Subject: [PATCH 1/2] fix: socket errors --- src/socket/socket-client.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/socket/socket-client.ts b/src/socket/socket-client.ts index a936567416..fc565b4bea 100644 --- a/src/socket/socket-client.ts +++ b/src/socket/socket-client.ts @@ -18,13 +18,17 @@ class SocketClient { private router: AppRouterInstance constructor() { - this.socket = io(`${GATEWAY_URL}/web`, { + // 如果 GATEWAY_URL 已经包含斜杠,确保它不以斜杠结尾 + const gatewayUrlWithoutTrailingSlash = GATEWAY_URL.replace(/\/$/, ''); + + // 拼接路径,确保路径之间没有多余的斜杠 + this.socket = io(`${gatewayUrlWithoutTrailingSlash}/web`, { timeout: 10000, reconnectionDelay: 3000, autoConnect: false, reconnectionAttempts: 3, transports: ['websocket'], - }) + }); } setRouter(router: AppRouterInstance) { From cc387cb9cf6b27100371c30e8f964b604546894b Mon Sep 17 00:00:00 2001 From: poboll Date: Sun, 17 Dec 2023 11:22:54 +0800 Subject: [PATCH 2/2] fix: socket errors Signed-off-by: poboll --- src/socket/socket-client.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/socket/socket-client.ts b/src/socket/socket-client.ts index fc565b4bea..b174219a5d 100644 --- a/src/socket/socket-client.ts +++ b/src/socket/socket-client.ts @@ -18,10 +18,8 @@ class SocketClient { private router: AppRouterInstance constructor() { - // 如果 GATEWAY_URL 已经包含斜杠,确保它不以斜杠结尾 const gatewayUrlWithoutTrailingSlash = GATEWAY_URL.replace(/\/$/, ''); - // 拼接路径,确保路径之间没有多余的斜杠 this.socket = io(`${gatewayUrlWithoutTrailingSlash}/web`, { timeout: 10000, reconnectionDelay: 3000,