2022-03-09 15:16:54 +09:00
|
|
|
import { VercelRequest, VercelResponse } from '@vercel/node';
|
2021-02-25 15:13:15 +09:00
|
|
|
import 'cross-fetch';
|
2020-08-31 08:41:53 +09:00
|
|
|
import whois from 'whois-json';
|
|
|
|
import { send, sendError } from '../../../util/http';
|
2019-07-31 02:08:41 +09:00
|
|
|
|
2019-12-24 01:57:07 +09:00
|
|
|
export default async function handler(
|
2022-03-09 15:16:54 +09:00
|
|
|
req: VercelRequest,
|
|
|
|
res: VercelResponse
|
2019-12-24 01:57:07 +09:00
|
|
|
): Promise<void> {
|
2020-08-31 08:41:53 +09:00
|
|
|
const { query } = req.query;
|
2019-07-31 02:08:41 +09:00
|
|
|
|
2020-06-19 16:15:53 +09:00
|
|
|
if (!query || typeof query !== 'string') {
|
2020-08-31 08:41:53 +09:00
|
|
|
return sendError(res, new Error('No query given'));
|
2019-07-31 02:08:41 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2020-08-31 08:41:53 +09:00
|
|
|
const response = await whois(query, { follow: 3, verbose: true });
|
|
|
|
const availability = response[0].data.domainName ? false : true;
|
|
|
|
send(res, { availability });
|
2022-03-09 15:16:54 +09:00
|
|
|
} catch (err: any) {
|
2020-08-31 08:41:53 +09:00
|
|
|
sendError(res, err);
|
2019-07-31 02:08:41 +09:00
|
|
|
}
|
|
|
|
}
|