2023-07-07 21:56:58 +02:00
|
|
|
const https = require('https');
|
2023-09-03 13:27:04 +02:00
|
|
|
const middleware = require('./_common/middleware'); // Make sure this path is correct
|
2023-07-07 21:56:58 +02:00
|
|
|
|
2023-09-03 13:27:04 +02:00
|
|
|
const handler = async (domain) => {
|
2023-07-07 21:56:58 +02:00
|
|
|
const dnsTypes = ['DNSKEY', 'DS', 'RRSIG'];
|
|
|
|
const records = {};
|
|
|
|
|
|
|
|
for (const type of dnsTypes) {
|
|
|
|
const options = {
|
|
|
|
hostname: 'dns.google',
|
|
|
|
path: `/resolve?name=${encodeURIComponent(domain)}&type=${type}`,
|
|
|
|
method: 'GET',
|
|
|
|
headers: {
|
|
|
|
'Accept': 'application/dns-json'
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
const dnsResponse = await new Promise((resolve, reject) => {
|
|
|
|
const req = https.request(options, res => {
|
|
|
|
let data = '';
|
|
|
|
|
|
|
|
res.on('data', chunk => {
|
|
|
|
data += chunk;
|
|
|
|
});
|
|
|
|
|
|
|
|
res.on('end', () => {
|
|
|
|
resolve(JSON.parse(data));
|
|
|
|
});
|
|
|
|
|
2023-07-10 00:23:50 +02:00
|
|
|
res.on('error', error => {
|
|
|
|
reject(error);
|
|
|
|
});
|
2023-07-07 21:56:58 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
req.end();
|
|
|
|
});
|
|
|
|
|
|
|
|
if (dnsResponse.Answer) {
|
|
|
|
records[type] = { isFound: true, answer: dnsResponse.Answer, response: dnsResponse.Answer };
|
|
|
|
} else {
|
2023-08-09 23:33:36 +02:00
|
|
|
records[type] = { isFound: false, answer: null, response: dnsResponse };
|
2023-07-07 21:56:58 +02:00
|
|
|
}
|
|
|
|
} catch (error) {
|
2023-08-09 23:33:36 +02:00
|
|
|
throw new Error(`Error fetching ${type} record: ${error.message}`); // This will be caught and handled by the commonMiddleware
|
2023-07-07 21:56:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-09 23:33:36 +02:00
|
|
|
return records;
|
2023-07-07 21:56:58 +02:00
|
|
|
};
|
2023-07-10 00:23:50 +02:00
|
|
|
|
2023-09-03 13:27:04 +02:00
|
|
|
module.exports = middleware(handler);
|
|
|
|
module.exports.handler = middleware(handler);
|
|
|
|
|