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:
26
api/services/gitlab.ts
Normal file
26
api/services/gitlab.ts
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user