Browse Source

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

imwald
fiatjaf_ 7 months ago committed by GitHub
parent
commit
b356115c9b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 8
      src/lib/url.ts

8
src/lib/url.ts

@ -5,7 +5,13 @@ 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 {
try { 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) 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)

Loading…
Cancel
Save