2022-02-03 16:15:14 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
exports = module.exports = {
|
|
|
|
|
resolve,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const assert = require('assert'),
|
|
|
|
|
constants = require('./constants.js'),
|
2023-06-30 18:34:53 +05:30
|
|
|
dns = require('dns');
|
2022-02-03 16:15:14 -08:00
|
|
|
|
|
|
|
|
// a note on TXT records. It doesn't have quotes ("") at the DNS level. Those quotes
|
|
|
|
|
// are added for DNS server software to enclose spaces. Such quotes may also be returned
|
|
|
|
|
// by the DNS REST API of some providers
|
|
|
|
|
async function resolve(hostname, rrtype, options) {
|
|
|
|
|
assert.strictEqual(typeof hostname, 'string');
|
|
|
|
|
assert.strictEqual(typeof rrtype, 'string');
|
2023-06-30 18:34:53 +05:30
|
|
|
assert(options && typeof options === 'object'); // { server, timeout }
|
2022-02-03 16:15:14 -08:00
|
|
|
|
2023-06-30 18:34:53 +05:30
|
|
|
const resolver = new dns.promises.Resolver({ timeout: options.timeout || 10000 });
|
2022-02-03 16:15:14 -08:00
|
|
|
|
2024-04-28 11:18:37 +02:00
|
|
|
if (constants.CLOUDRON) resolver.setServers([ options.server || '127.0.0.150' ]); // unbound runs here
|
2022-02-03 16:15:14 -08:00
|
|
|
|
2023-06-30 18:34:53 +05:30
|
|
|
const result = await resolver.resolve(hostname, rrtype);
|
2022-02-03 16:15:14 -08:00
|
|
|
|
2022-03-08 17:10:04 -08:00
|
|
|
// when you query a random record, it errors with ENOTFOUND. But, if you query a record which has a different type
|
|
|
|
|
// we sometimes get empty array and sometimes ENODATA. for TXT records, result is 2d array of strings
|
2022-02-03 16:15:14 -08:00
|
|
|
return result;
|
|
|
|
|
}
|