fix: 🐛
This commit is contained in:
parent
7826364003
commit
b576afb971
6 changed files with 23 additions and 11 deletions
|
|
@ -4,15 +4,20 @@ export function isWebsocketUrl(url: string): boolean {
|
|||
|
||||
// copy from nostr-tools/utils
|
||||
export function normalizeUrl(url: string): string {
|
||||
if (url.indexOf('://') === -1) url = 'wss://' + url
|
||||
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:'))
|
||||
p.port = ''
|
||||
p.searchParams.sort()
|
||||
p.hash = ''
|
||||
return p.toString()
|
||||
try {
|
||||
if (url.indexOf('://') === -1) url = 'wss://' + url
|
||||
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:'))
|
||||
p.port = ''
|
||||
p.searchParams.sort()
|
||||
p.hash = ''
|
||||
return p.toString()
|
||||
} catch {
|
||||
console.error('Invalid URL:', url)
|
||||
return ''
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeHttpUrl(url: string): string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue