1
0
mirror of https://github.com/uetchy/namae.git synced 2025-03-18 04:50:32 +09:00
Yasuaki Uechi 4343d0f633 fix: theme-color
chore: fix margin
chore: update deps
2021-09-25 21:05:10 +09:00

30 lines
796 B
TypeScript

import isURL from 'validator/lib/isURL';
import { send, sendError, fetch } from '../../../util/http';
import { VercelRequest, VercelResponse } from '@vercel/node';
export default async function handler(
req: VercelRequest,
res: VercelResponse
): Promise<void> {
const { query } = req.query;
if (!query || typeof query !== 'string') {
return sendError(res, new Error('no query given'));
}
if (!isURL(query)) {
return sendError(res, new Error('Invalid URL: ' + query));
}
try {
const response = await fetch(`https://${query}`);
const availability = response.status === 404;
send(res, { availability });
} catch (err) {
if ((err as any).code === 'ENOTFOUND') {
return send(res, { availability: true });
}
sendError(res, err as any);
}
}