Replace of promisify for dns with dns.promises

This commit is contained in:
CosminPerRam 2023-10-14 19:53:07 +03:00
parent 6b454dd4d2
commit 5af13e283e
1 changed files with 3 additions and 7 deletions

View File

@ -1,9 +1,5 @@
import * as dns from 'node:dns'
import dns from 'node:dns'
import punycode from 'punycode/punycode.js'
import { promisify } from 'node:util'
const dnsLookupAsync = promisify(dns.lookup)
const dnsResolveAsync = promisify(dns.resolve)
export default class DnsResolver {
/**
@ -42,7 +38,7 @@ export default class DnsResolver {
this.logger.debug('SRV Resolve: ' + srvRecordPrefix + '.' + host)
let records
try {
records = await dnsResolveAsync(srvRecordPrefix + '.' + host, 'SRV')
records = await dns.promises.resolve(srvRecordPrefix + '.' + host, 'SRV')
if (records.length >= 1) {
this.logger.debug('Found SRV Records: ', records)
const record = records[0]
@ -63,7 +59,7 @@ export default class DnsResolver {
}
this.logger.debug('Standard Resolve: ' + host)
const dnsResult = await dnsLookupAsync(host, ipFamily)
const dnsResult = await dns.promises.lookup(host, ipFamily)
// For some reason, this sometimes returns a string address rather than an object.
// I haven't been able to reproduce, but it's been reported on the issue tracker.
let address