fix: default to ws:// instead of wss:// for localhost (#465)

This commit is contained in:
fiatjaf_
2025-08-03 22:05:20 -03:00
committed by GitHub
parent f9cbcda7e8
commit b356115c9b

View File

@@ -5,7 +5,13 @@ export function isWebsocketUrl(url: string): boolean {
// copy from nostr-tools/utils
export function normalizeUrl(url: string): string {
try {
if (url.indexOf('://') === -1) url = 'wss://' + url
if (url.indexOf('://') === -1) {
if (url.startsWith('localhost:') || url.startsWith('localhost/')) {
url = 'ws://' + url
} else {
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)