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:
21
api/services/github.js
Normal file
21
api/services/github.js
Normal file
@@ -0,0 +1,21 @@
|
||||
const fetch = require('isomorphic-unfetch')
|
||||
|
||||
async function getAvailability(name) {
|
||||
const response = await fetch(`https://github.com/${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 })
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user