fix: only lookup localhost for DNS lookups

This commit is contained in:
Randolf J 2022-06-04 01:04:11 +02:00
parent eb7cd717ed
commit 1b025b4c84

View File

@ -23,13 +23,15 @@ export class NodeWebSocketTransport implements ConnectionTransport {
// TODO(jrandolf): Starting in Node 17, IPv6 is favoured over IPv4 due to a change
// in a default option:
// - https://github.com/nodejs/node/issues/40537,
// Due to this, we parse and resolve the hostname manually with the previous
// behavior according to:
// Due to this, for Firefox, we must parse and resolve the `localhost` hostname
// manually with the previous behavior according to:
// - https://nodejs.org/api/dns.html#dnslookuphostname-options-callback
// because of https://bugzilla.mozilla.org/show_bug.cgi?id=1769994.
const url = new URL(urlString);
if (url.hostname === 'localhost') {
const { address } = await dns.lookup(url.hostname, { verbatim: false });
url.hostname = address;
}
return new Promise((resolve, reject) => {
const ws = new NodeWebSocket(url, [], {