mirror of
https://github.com/uetchy/namae.git
synced 2025-08-20 18:08:11 +09:00
fix: support new vercel style
This commit is contained in:
24
api/services/npm-org/[query].ts
Normal file
24
api/services/npm-org/[query].ts
Normal file
@@ -0,0 +1,24 @@
|
||||
import npmName from 'npm-name';
|
||||
import {send, sendError} from '../../../util/http';
|
||||
import {NowRequest, NowResponse} from '@vercel/node';
|
||||
|
||||
export default async function handler(
|
||||
req: NowRequest,
|
||||
res: NowResponse,
|
||||
): Promise<void> {
|
||||
const {query} = req.query;
|
||||
|
||||
if (!query || typeof query !== 'string') {
|
||||
return sendError(res, new Error('No query given'));
|
||||
}
|
||||
|
||||
try {
|
||||
const availability = await npmName(`@${query}`);
|
||||
send(res, {availability});
|
||||
} catch (err) {
|
||||
if (err.code === 'ENOTFOUND') {
|
||||
return send(res, {availability: true});
|
||||
}
|
||||
sendError(res, err);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user