Browse Source

check for localhost typos

imwald
Silberengel 5 months ago
parent
commit
e902db9dc4
  1. 7
      src/lib/url.ts
  2. 10
      src/services/client.service.ts
  3. 10
      src/services/relay-selection.service.ts

7
src/lib/url.ts

@ -20,6 +20,13 @@ export function normalizeUrl(url: string): string { @@ -20,6 +20,13 @@ export function normalizeUrl(url: string): string {
} else if (p.protocol === 'http:') {
p.protocol = 'ws:'
}
// Normalize localhost and local network addresses to always use ws:// instead of wss://
// This fixes the common typo where people use wss:// for local relays
if (isLocalNetworkUrl(p.toString())) {
p.protocol = 'ws:'
}
if ((p.port === '80' && p.protocol === 'ws:') || (p.port === '443' && p.protocol === 'wss:')) {
p.port = ''
}

10
src/services/client.service.ts

@ -1570,9 +1570,15 @@ class ClientService extends EventTarget { @@ -1570,9 +1570,15 @@ class ClientService extends EventTarget {
return relays
}
const normalizedBlocked = blockedRelays.map(url => normalizeUrl(url) || url)
// Helper function to safely normalize URLs
const safeNormalize = (url: string): string => {
const normalized = normalizeUrl(url)
return normalized || url
}
const normalizedBlocked = blockedRelays.map(safeNormalize)
return relays.filter(relay => {
const normalizedRelay = normalizeUrl(relay) || relay
const normalizedRelay = safeNormalize(relay)
return !normalizedBlocked.includes(normalizedRelay)
})
}

10
src/services/relay-selection.service.ts

@ -482,9 +482,15 @@ class RelaySelectionService { @@ -482,9 +482,15 @@ class RelaySelectionService {
return relays
}
const normalizedBlocked = blockedRelays.map(url => normalizeUrl(url) || url)
// Helper function to safely normalize URLs
const safeNormalize = (url: string): string => {
const normalized = normalizeUrl(url)
return normalized || url
}
const normalizedBlocked = blockedRelays.map(safeNormalize)
return relays.filter(relay => {
const normalizedRelay = normalizeUrl(relay) || relay
const normalizedRelay = safeNormalize(relay)
return !normalizedBlocked.includes(normalizedRelay)
})
}

Loading…
Cancel
Save