|
|
|
@ -4,15 +4,20 @@ export function isWebsocketUrl(url: string): boolean { |
|
|
|
|
|
|
|
|
|
|
|
// copy from nostr-tools/utils
|
|
|
|
// copy from nostr-tools/utils
|
|
|
|
export function normalizeUrl(url: string): string { |
|
|
|
export function normalizeUrl(url: string): string { |
|
|
|
if (url.indexOf('://') === -1) url = 'wss://' + url |
|
|
|
try { |
|
|
|
const p = new URL(url) |
|
|
|
if (url.indexOf('://') === -1) url = 'wss://' + url |
|
|
|
p.pathname = p.pathname.replace(/\/+/g, '/') |
|
|
|
const p = new URL(url) |
|
|
|
if (p.pathname.endsWith('/')) p.pathname = p.pathname.slice(0, -1) |
|
|
|
p.pathname = p.pathname.replace(/\/+/g, '/') |
|
|
|
if ((p.port === '80' && p.protocol === 'ws:') || (p.port === '443' && p.protocol === 'wss:')) |
|
|
|
if (p.pathname.endsWith('/')) p.pathname = p.pathname.slice(0, -1) |
|
|
|
p.port = '' |
|
|
|
if ((p.port === '80' && p.protocol === 'ws:') || (p.port === '443' && p.protocol === 'wss:')) |
|
|
|
p.searchParams.sort() |
|
|
|
p.port = '' |
|
|
|
p.hash = '' |
|
|
|
p.searchParams.sort() |
|
|
|
return p.toString() |
|
|
|
p.hash = '' |
|
|
|
|
|
|
|
return p.toString() |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
console.error('Invalid URL:', url) |
|
|
|
|
|
|
|
return '' |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function normalizeHttpUrl(url: string): string { |
|
|
|
export function normalizeHttpUrl(url: string): string { |
|
|
|
|