mirror of
https://github.com/uetchy/namae.git
synced 2025-08-20 01:48:12 +09:00
fix: better whois impl
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { VercelRequest, VercelResponse } from '@vercel/node';
|
||||
import 'cross-fetch';
|
||||
import whois from 'whois-json';
|
||||
import whoiser from 'whoiser';
|
||||
import { send, sendError } from '../../../util/http';
|
||||
|
||||
export default async function handler(
|
||||
@@ -14,9 +14,17 @@ export default async function handler(
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await whois(query, { follow: 3, verbose: true });
|
||||
const availability = response[0].data.domainName ? false : true;
|
||||
send(res, { availability });
|
||||
const response = await whoiser(query, { follow: 1, timeout: 5000 });
|
||||
const first = Object.values<any>(response)[0];
|
||||
if (first.error) {
|
||||
throw new Error(`Got error while querying for ${query}: ${first.error}`);
|
||||
}
|
||||
try {
|
||||
const availability = first['Domain Status'].length > 0 ? false : true;
|
||||
send(res, { availability });
|
||||
} catch (err) {
|
||||
console.log(response);
|
||||
}
|
||||
} catch (err: any) {
|
||||
sendError(res, err);
|
||||
}
|
||||
|
Reference in New Issue
Block a user