Skip to content

Commit dec39a3

Browse files
committed
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
1 parent 7a39da9 commit dec39a3

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/app.ts

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,24 @@ async function mdnsLookup(
119119
return lookup(name, { verbatim: true }, opts);
120120
}
121121

122-
if (name && name.endsWith('.local')) {
123-
return mdnsLookup(name, opts, cb);
124-
}
125-
126-
return lookup(name, Object.assign({ verbatim: true }, opts), cb);
122+
// Try a regular dns lookup first
123+
return lookup(
124+
name,
125+
Object.assign({ verbatim: true }, opts),
126+
(error: any, address: string, family: number) => {
127+
if (error == null) {
128+
return cb(null, address, family);
129+
}
130+
131+
// If the regular lookup fails, we perform a mdns lookup if the
132+
// name ends with .local
133+
if (name && name.endsWith('.local')) {
134+
return mdnsLookup(name, opts, cb);
135+
}
136+
137+
return cb(error);
138+
},
139+
);
127140
};
128141
})();
129142

0 commit comments

Comments
 (0)