From bc470c226f0b2ad5f3ce39b2bf4ef5ababe491e1 Mon Sep 17 00:00:00 2001 From: baiqi Date: Tue, 13 Aug 2024 15:07:19 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E6=89=A7=E8=A1=8C=E5=8D=8F=E8=AE=AE=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/api/modules/project-management/commonScript.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/api/modules/project-management/commonScript.ts b/frontend/src/api/modules/project-management/commonScript.ts index f98795dc5f..fc76a97178 100644 --- a/frontend/src/api/modules/project-management/commonScript.ts +++ b/frontend/src/api/modules/project-management/commonScript.ts @@ -95,10 +95,16 @@ export function getFormApiImportModuleCount(data: TableQueryParams) { export function testCommonScript(data: TestScriptType) { return MSR.post({ url: TestScriptUrl, data }); } -// apiSocket 建立连接 +/** + * apiSocket 建立连接 + * @param url 连接地址 + * @param host 连接主机 + */ export const apiSocket = (url: string, host?: string) => { let protocol = 'ws://'; - if (window.location.protocol === 'https:' || host?.startsWith('https')) { + + // 根据传入的 url 判断是否为 https 协议 + if (!host?.startsWith('http') && (window.location.protocol === 'https:' || host?.startsWith('https'))) { protocol = 'wss://'; } const uri = protocol + (host?.split('://')[1] || window.location.host) + url;