2019-08-30 16:40:22 +09:00
|
|
|
import npmName from 'npm-name'
|
|
|
|
import { send, sendError, fetch, NowRequest, NowResponse } from '../util/http'
|
2019-07-31 01:12:51 +09:00
|
|
|
|
2019-08-30 16:40:22 +09:00
|
|
|
export default async function handler(req: NowRequest, res: NowResponse) {
|
2019-08-06 01:17:45 +09:00
|
|
|
const { query } = req.query
|
2019-07-31 01:12:51 +09:00
|
|
|
|
2019-08-06 01:17:45 +09:00
|
|
|
if (!query) {
|
2019-08-05 22:59:39 +09:00
|
|
|
return sendError(res, new Error('no query given'))
|
2019-07-31 01:12:51 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2019-08-06 01:17:45 +09:00
|
|
|
const availability = await npmName(`@${query}`)
|
|
|
|
send(res, { availability })
|
2019-07-31 01:12:51 +09:00
|
|
|
} catch (err) {
|
2019-08-01 13:22:03 +09:00
|
|
|
sendError(res, err)
|
2019-07-31 01:12:51 +09:00
|
|
|
}
|
|
|
|
}
|