Try MDNS lookup only if regular DNS lookup fails

This is meant to allow users to configure their device to
resolve `.local` queries via dnsmasq by modifying config.json, e.g. `dnsServers":
"/bob.local/172.17.0.33`.

This would fail before as MDNS lookups would always come first

Change-type: minor
This commit is contained in:
Felipe Lalanne 2023-12-28 15:52:06 -03:00 committed by Felipe Lalanne
parent 7a39da92b7
commit dec39a35d4

View File

@ -119,11 +119,24 @@ async function mdnsLookup(
return lookup(name, { verbatim: true }, opts);
}
if (name && name.endsWith('.local')) {
return mdnsLookup(name, opts, cb);
}
// Try a regular dns lookup first
return lookup(
name,
Object.assign({ verbatim: true }, opts),
(error: any, address: string, family: number) => {
if (error == null) {
return cb(null, address, family);
}
return lookup(name, Object.assign({ verbatim: true }, opts), cb);
// If the regular lookup fails, we perform a mdns lookup if the
// name ends with .local
if (name && name.endsWith('.local')) {
return mdnsLookup(name, opts, cb);
}
return cb(error);
},
);
};
})();