1
0
mirror of https://github.com/uetchy/namae.git synced 2025-08-21 02:08:12 +09:00

feat: rubygems

This commit is contained in:
2019-08-02 16:27:05 +09:00
parent d856caadde
commit 72a70fe1a4
5 changed files with 72 additions and 4 deletions

20
api/services/rubygems.js Normal file
View File

@@ -0,0 +1,20 @@
const fetch = require('isomorphic-unfetch')
const { send, sendError } = require('../util/http')
module.exports = async (req, res) => {
const name = req.query.name
if (!name) {
return res.status(400).json({ error: 'no query given' })
}
try {
const response = await fetch(
`https://rubygems.org/gems/${encodeURIComponent(name)}`
)
const availability = response.status !== 200
send(res, availability)
} catch (err) {
sendError(res, err)
}
}