Browse Source

fix: 🐛

imwald
codytseng 8 months ago
parent
commit
3441cdc021
  1. 16
      src/lib/url.ts

16
src/lib/url.ts

@ -9,8 +9,14 @@ export function normalizeUrl(url: string): string {
const p = new URL(url) const p = new URL(url)
p.pathname = p.pathname.replace(/\/+/g, '/') p.pathname = p.pathname.replace(/\/+/g, '/')
if (p.pathname.endsWith('/')) p.pathname = p.pathname.slice(0, -1) 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.port = ''
}
p.searchParams.sort() p.searchParams.sort()
p.hash = '' p.hash = ''
return p.toString() return p.toString()
@ -26,11 +32,17 @@ export function normalizeHttpUrl(url: string): string {
const p = new URL(url) const p = new URL(url)
p.pathname = p.pathname.replace(/\/+/g, '/') p.pathname = p.pathname.replace(/\/+/g, '/')
if (p.pathname.endsWith('/')) p.pathname = p.pathname.slice(0, -1) 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 ( if (
(p.port === '80' && p.protocol === 'http:') || (p.port === '80' && p.protocol === 'http:') ||
(p.port === '443' && p.protocol === 'https:') (p.port === '443' && p.protocol === 'https:')
) ) {
p.port = '' p.port = ''
}
p.searchParams.sort() p.searchParams.sort()
p.hash = '' p.hash = ''
return p.toString() return p.toString()

Loading…
Cancel
Save