1
0
mirror of https://github.com/uetchy/namae.git synced 2025-03-19 05:20:33 +09:00
namae/api/services/domain/[query].ts

23 lines
598 B
TypeScript
Raw Normal View History

2019-09-17 14:30:26 +09:00
import whois from 'whois-json';
2020-06-19 16:15:53 +09:00
import {send, sendError} from '../../../util/http';
import {NowRequest, NowResponse} from '@vercel/node';
2019-07-31 02:08:41 +09:00
2019-12-24 01:57:07 +09:00
export default async function handler(
req: NowRequest,
res: NowResponse,
): Promise<void> {
2019-09-17 14:30:26 +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') {
2019-12-10 18:33:39 +09:00
return sendError(res, new Error('No query given'));
2019-07-31 02:08:41 +09:00
}
try {
2019-09-17 14:30:26 +09:00
const response = await whois(query, {follow: 3, verbose: true});
const availability = response[0].data.domainName ? false : true;
send(res, {availability});
2019-07-31 02:08:41 +09:00
} catch (err) {
2019-09-17 14:30:26 +09:00
sendError(res, err);
2019-07-31 02:08:41 +09:00
}
}