mirror of
https://github.com/uetchy/namae.git
synced 2025-03-17 20:40:32 +09:00
25 lines
642 B
TypeScript
25 lines
642 B
TypeScript
import {send, sendError, fetch, NowRequest, NowResponse} from '../util/http';
|
|
import nodeFetch from 'node-fetch';
|
|
|
|
export default async function handler(req: NowRequest, res: NowResponse) {
|
|
const {query} = req.query;
|
|
|
|
if (!query) {
|
|
return sendError(res, new Error('No query given'));
|
|
}
|
|
|
|
if (/[^a-zA-Z0-9_-]/.test(query)) {
|
|
return sendError(res, new Error('Invalid characters'));
|
|
}
|
|
|
|
try {
|
|
const response = await nodeFetch(`https://gitlab.com/${query}`, {
|
|
redirect: 'manual',
|
|
});
|
|
const availability = response.status === 302;
|
|
send(res, {availability});
|
|
} catch (err) {
|
|
sendError(res, err);
|
|
}
|
|
}
|