Skip to content

Commit 07d90ab

Browse files
committed
use Resolver class of dns/promises, avoiding messing with other network calls
1 parent d65f170 commit 07d90ab

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

lib/domain-verification.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { requestCertificate, getCertificateStatus, describeCertificate } from '@/api/acm'
2-
import { promises as dnsPromises } from 'node:dns'
2+
import { Resolver } from 'node:dns/promises'
33

44
// Issue a certificate for a custom domain
55
export async function issueDomainCertificate (domainName) {
@@ -69,11 +69,12 @@ export async function verifyDomainDNS (domainName, verificationTxt, verification
6969
}
7070

7171
// by default use cloudflare DNS resolver
72-
dnsPromises.setServers([process.env.DNS_RESOLVER || '1.1.1.1'])
72+
const resolver = new Resolver()
73+
resolver.setServers([process.env.DNS_RESOLVER || '1.1.1.1'])
7374

7475
// TXT Records checking
7576
try {
76-
const txtRecords = await dnsPromises.resolve(txtHost, 'TXT')
77+
const txtRecords = await resolver.resolveTxt(txtHost)
7778
const txtText = txtRecords.flat().join(' ')
7879

7980
// the TXT record should include the verificationTxt that we have in the database
@@ -88,7 +89,7 @@ export async function verifyDomainDNS (domainName, verificationTxt, verification
8889

8990
// CNAME Records checking
9091
try {
91-
const cnameRecords = await dnsPromises.resolve(domainName, 'CNAME')
92+
const cnameRecords = await resolver.resolveCname(domainName)
9293

9394
// the CNAME record should include the cname that we have in the database
9495
result.cnameValid = cnameRecords.some(record =>

0 commit comments

Comments
 (0)