1
0
mirror of https://github.com/uetchy/namae.git synced 2025-03-17 20:40:32 +09:00
namae/api/services/rubygems.js

20 lines
446 B
JavaScript
Raw Normal View History

2019-08-05 22:59:39 +09:00
const { send, sendError, fetch } = require('../util/http')
2019-08-02 16:27:05 +09:00
module.exports = async (req, res) => {
2019-08-06 01:17:45 +09:00
const { query } = req.query
2019-08-02 16:27:05 +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-08-02 16:27:05 +09:00
}
try {
const response = await fetch(
2019-08-06 01:17:45 +09:00
`https://rubygems.org/gems/${encodeURIComponent(query)}`
2019-08-02 16:27:05 +09:00
)
const availability = response.status !== 200
2019-08-06 01:17:45 +09:00
send(res, { availability })
2019-08-02 16:27:05 +09:00
} catch (err) {
sendError(res, err)
}
}