Skip to content

Commit

Permalink
dns: make promise API fully constructed from lib/internal/dns/promises
Browse files Browse the repository at this point in the history
  • Loading branch information
F3n67u committed Jun 18, 2022
1 parent fe776b8 commit 280b9d5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 0 additions & 2 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,6 @@ ObjectDefineProperties(module.exports, {
get() {
if (promises === null) {
promises = require('internal/dns/promises');
promises.setServers = defaultResolverSetServers;
promises.setDefaultResultOrder = setDefaultResultOrder;
}
return promises;
}
Expand Down
4 changes: 1 addition & 3 deletions lib/dns/promises.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict';

const dnsPromises = require('internal/dns/promises');
dnsPromises.setServers = require('dns').setServers;
module.exports = dnsPromises;
module.exports = require('internal/dns/promises');
17 changes: 16 additions & 1 deletion lib/internal/dns/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const {
validateTries,
emitInvalidHostnameWarning,
getDefaultVerbatim,
setDefaultResultOrder,
setDefaultResolver,
} = require('internal/dns/utils');
const { codes, dnsException } = require('internal/errors');
const { toASCII } = require('internal/idna');
Expand Down Expand Up @@ -322,6 +324,19 @@ Resolver.prototype.resolve = function resolve(hostname, rrtype) {
return ReflectApply(resolver, this, [hostname]);
};

function defaultResolverSetServers(servers) {
const resolver = new Resolver();

module.exports = { lookup, lookupService, Resolver };
resolver.setServers(servers);
setDefaultResolver(resolver);
bindDefaultResolver(module.exports, Resolver.prototype);
}

module.exports = {
lookup,
lookupService,
Resolver,
setDefaultResultOrder,
setServers: defaultResolverSetServers,
};
bindDefaultResolver(module.exports, Resolver.prototype);

0 comments on commit 280b9d5

Please sign in to comment.