2022-07-09 21:29:36 +02:00
|
|
|
const dns = require('dns');
|
2023-08-09 23:33:36 +02:00
|
|
|
const middleware = require('./_common/middleware');
|
2022-07-09 21:29:36 +02:00
|
|
|
|
2023-08-09 23:33:36 +02:00
|
|
|
const lookupAsync = (address) => {
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
dns.lookup(address, (err, ip, family) => {
|
|
|
|
if (err) {
|
|
|
|
reject(err);
|
|
|
|
} else {
|
|
|
|
resolve({ ip, family });
|
|
|
|
}
|
|
|
|
});
|
2022-07-09 21:29:36 +02:00
|
|
|
});
|
|
|
|
};
|
2023-07-10 00:23:50 +02:00
|
|
|
|
2023-08-09 23:33:36 +02:00
|
|
|
const handler = async (url) => {
|
|
|
|
const address = url.replaceAll('https://', '').replaceAll('http://', '');
|
|
|
|
return await lookupAsync(address);
|
2023-07-10 00:23:50 +02:00
|
|
|
};
|
2023-08-09 23:33:36 +02:00
|
|
|
|
2023-09-03 13:27:04 +02:00
|
|
|
|
|
|
|
module.exports = middleware(handler);
|
|
|
|
module.exports.handler = middleware(handler);
|