mirror of
https://github.com/Lissy93/web-check.git
synced 2024-11-26 10:13:27 +01:00
24 lines
535 B
JavaScript
24 lines
535 B
JavaScript
import dns from 'dns';
|
|
import middleware from './_common/middleware.js';
|
|
|
|
const lookupAsync = (address) => {
|
|
return new Promise((resolve, reject) => {
|
|
dns.lookup(address, (err, ip, family) => {
|
|
if (err) {
|
|
reject(err);
|
|
} else {
|
|
resolve({ ip, family });
|
|
}
|
|
});
|
|
});
|
|
};
|
|
|
|
const ipHandler = async (url) => {
|
|
const address = url.replaceAll('https://', '').replaceAll('http://', '');
|
|
return await lookupAsync(address);
|
|
};
|
|
|
|
|
|
export const handler = middleware(ipHandler);
|
|
export default handler;
|