normalizeURL prepends ws:// when necessary.

This commit is contained in:
fiatjaf 2024-01-20 12:48:28 -03:00
parent 12147d4fee
commit 967d7fe63a
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
1 changed files with 1 additions and 0 deletions

View File

@ -4,6 +4,7 @@ export const utf8Decoder = new TextDecoder('utf-8')
export const utf8Encoder = new TextEncoder()
export function normalizeURL(url: string): string {
if (url.indexOf('://') === -1) url = 'wss://' + url
let p = new URL(url)
p.pathname = p.pathname.replace(/\/+/g, '/')
if (p.pathname.endsWith('/')) p.pathname = p.pathname.slice(0, -1)