bun
bun copied to clipboard
DoH dns lookup with cloudflare
This dns fallback uses cloudflare DoH to implement a basic lookup
The unexpected implementation structure stems from the actual DNS API https://nodejs.org/dist/latest-v18.x/docs/api/dns.html .
Node v6 only had the top-level methods like dns.resolve. Node v8 added the Resolver class and v10 added the promises API
Constants
Constants are in a separate file because each constant is actually exported twice!
https://nodejs.org/dist/latest-v18.x/docs/api/dns.html#error-codes
The dnsPromises API also exports the above error codes, e.g., dnsPromises.NODATA.
For example, the main dns module has to export the constant CONNREFUSED AND it must be an element in the promises export. The separate script reduces line noise but it can be duplicated in the main script if that is preferable.
Resolver Classes and Methods
The dns module exposes a resolve4 function AND the Resolver class has a resolve4 method. The main difference is that the former uses the default settings (tuned with dns.setServers) and the latter uses instance settings (tuned with the Resolver#setServers method). The exported functions are neatly implemented using an internal instance of Resolver and exposing bound methods.