2024-05-06 22:51:32 +02:00
|
|
|
import dns from 'dns';
|
|
|
|
import middleware from './_common/middleware.js';
|
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
|
|
|
|
2024-05-06 22:51:32 +02:00
|
|
|
const ipHandler = async (url) => {
|
2023-08-09 23:33:36 +02:00
|
|
|
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
|
|
|
|
2024-05-06 22:51:32 +02:00
|
|
|
export const handler = middleware(ipHandler);
|
|
|
|
export default handler;
|