1
0
mirror of https://github.com/uetchy/namae.git synced 2025-08-20 18:08:11 +09:00

chore: split app into api and web

This commit is contained in:
2019-07-31 13:11:00 +09:00
parent 44c46f329d
commit 11e7f0e9e0
50 changed files with 10730 additions and 472 deletions

23
api/services/cratesio.js Normal file
View File

@@ -0,0 +1,23 @@
const fetch = require('isomorphic-unfetch')
async function getAvailability(name) {
const response = await fetch(
`https://crates.io/api/v1/crates/${encodeURIComponent(name)}`
)
return response.status !== 200
}
module.exports = async (req, res) => {
const name = req.query.name
if (!name) {
return res.status(400).json({ error: 'no query given' })
}
try {
const availability = await getAvailability(name)
res.json({ availability })
} catch (err) {
res.status(400).json({ error: err.message })
}
}