2019-12-24 01:57:07 +09:00
|
|
|
import {send, sendError, NowRequest, NowResponse} from '../util/http';
|
2019-12-10 18:33:39 +09:00
|
|
|
import nodeFetch from 'node-fetch';
|
2019-10-16 14:14:02 +09:00
|
|
|
|
2019-12-24 01:57:07 +09:00
|
|
|
export default async function handler(
|
|
|
|
req: NowRequest,
|
|
|
|
res: NowResponse,
|
|
|
|
): Promise<void> {
|
2019-10-16 14:14:02 +09:00
|
|
|
const {query} = req.query;
|
|
|
|
|
|
|
|
if (!query) {
|
2019-12-10 18:33:39 +09:00
|
|
|
return sendError(res, new Error('No query given'));
|
2019-10-16 14:14:02 +09:00
|
|
|
}
|
|
|
|
|
2019-12-10 18:33:39 +09:00
|
|
|
if (/[^a-zA-Z0-9_-]/.test(query)) {
|
|
|
|
return sendError(res, new Error('Invalid characters'));
|
2019-10-16 14:14:02 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2019-12-10 18:33:39 +09:00
|
|
|
const response = await nodeFetch(`https://gitlab.com/${query}`, {
|
|
|
|
redirect: 'manual',
|
|
|
|
});
|
2019-10-16 14:14:02 +09:00
|
|
|
const availability = response.status === 302;
|
|
|
|
send(res, {availability});
|
|
|
|
} catch (err) {
|
|
|
|
sendError(res, err);
|
|
|
|
}
|
|
|
|
}
|