fix(接口测试): 本地执行协议调整

This commit is contained in:
baiqi 2024-08-13 15:07:19 +08:00 committed by Craftsman
parent a9f6679319
commit bc470c226f
1 changed files with 8 additions and 2 deletions

View File

@ -95,10 +95,16 @@ export function getFormApiImportModuleCount(data: TableQueryParams) {
export function testCommonScript(data: TestScriptType) { export function testCommonScript(data: TestScriptType) {
return MSR.post({ url: TestScriptUrl, data }); return MSR.post({ url: TestScriptUrl, data });
} }
// apiSocket 建立连接 /**
* apiSocket
* @param url
* @param host
*/
export const apiSocket = (url: string, host?: string) => { export const apiSocket = (url: string, host?: string) => {
let protocol = 'ws://'; 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://'; protocol = 'wss://';
} }
const uri = protocol + (host?.split('://')[1] || window.location.host) + url; const uri = protocol + (host?.split('://')[1] || window.location.host) + url;