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
PR-URL: nodejs#43227
Refs: nodejs#43198
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Minwoo Jung <[email protected]>
  • Loading branch information
F3n67u committed Jun 24, 2022
1 parent f26cd67 commit 2dae13f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
2 changes: 0 additions & 2 deletions lib/dns.js
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,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');
11 changes: 11 additions & 0 deletions lib/internal/dns/promises.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const {
emitInvalidHostnameWarning,
getDefaultVerbatim,
errorCodes: dnsErrorCodes,
setDefaultResultOrder,
setDefaultResolver,
} = require('internal/dns/utils');
const {
NODATA,
Expand Down Expand Up @@ -349,11 +351,20 @@ Resolver.prototype.resolve = function resolve(hostname, rrtype) {
return ReflectApply(resolver, this, [hostname]);
};

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

resolver.setServers(servers);
setDefaultResolver(resolver);
bindDefaultResolver(module.exports, Resolver.prototype);
}

module.exports = {
lookup,
lookupService,
Resolver,
setDefaultResultOrder,
setServers: defaultResolverSetServers,

// ERROR CODES
NODATA,
Expand Down

0 comments on commit 2dae13f

Please sign in to comment.