1
0
mirror of https://github.com/uetchy/namae.git synced 2025-08-20 18:08:11 +09:00

feat: add Netlify and GitLab

This commit is contained in:
2019-10-16 14:14:02 +09:00
parent 82aaea6276
commit 54cd7be854
10 changed files with 121 additions and 3 deletions

26
api/services/gitlab.ts Normal file
View File

@@ -0,0 +1,26 @@
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 (
/[^\w-]/.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);
}
}