From 3441cdc0212960d0b9ecd15a8e6ac02b98872cae Mon Sep 17 00:00:00 2001 From: codytseng Date: Tue, 8 Jul 2025 17:59:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/url.ts | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/lib/url.ts b/src/lib/url.ts index 44121258..c8b301cb 100644 --- a/src/lib/url.ts +++ b/src/lib/url.ts @@ -9,8 +9,14 @@ export function normalizeUrl(url: string): string { const p = new URL(url) p.pathname = p.pathname.replace(/\/+/g, '/') if (p.pathname.endsWith('/')) p.pathname = p.pathname.slice(0, -1) - if ((p.port === '80' && p.protocol === 'ws:') || (p.port === '443' && p.protocol === 'wss:')) + if (p.protocol === 'https:') { + p.protocol = 'wss:' + } else if (p.protocol === 'http:') { + p.protocol = 'ws:' + } + if ((p.port === '80' && p.protocol === 'ws:') || (p.port === '443' && p.protocol === 'wss:')) { p.port = '' + } p.searchParams.sort() p.hash = '' return p.toString() @@ -26,11 +32,17 @@ export function normalizeHttpUrl(url: string): string { const p = new URL(url) p.pathname = p.pathname.replace(/\/+/g, '/') if (p.pathname.endsWith('/')) p.pathname = p.pathname.slice(0, -1) + if (p.protocol === 'wss:') { + p.protocol = 'https:' + } else if (p.protocol === 'ws:') { + p.protocol = 'http:' + } if ( (p.port === '80' && p.protocol === 'http:') || (p.port === '443' && p.protocol === 'https:') - ) + ) { p.port = '' + } p.searchParams.sort() p.hash = '' return p.toString()