mirror of
https://github.com/Lissy93/web-check.git
synced 2025-08-09 05:04:31 +02:00
Rename endpoints to be the same as job IDs
This commit is contained in:
52
api/dnssec.js
Normal file
52
api/dnssec.js
Normal file
@ -0,0 +1,52 @@
|
||||
const https = require('https');
|
||||
const commonMiddleware = require('./_common/middleware'); // Make sure this path is correct
|
||||
|
||||
const fetchDNSRecords = async (domain, event, context) => {
|
||||
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));
|
||||
});
|
||||
|
||||
res.on('error', error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
|
||||
req.end();
|
||||
});
|
||||
|
||||
if (dnsResponse.Answer) {
|
||||
records[type] = { isFound: true, answer: dnsResponse.Answer, response: dnsResponse.Answer };
|
||||
} else {
|
||||
records[type] = { isFound: false, answer: null, response: dnsResponse };
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(`Error fetching ${type} record: ${error.message}`); // This will be caught and handled by the commonMiddleware
|
||||
}
|
||||
}
|
||||
|
||||
return records;
|
||||
};
|
||||
|
||||
exports.handler = commonMiddleware(fetchDNSRecords);
|
Reference in New Issue
Block a user