mirror of
https://github.com/uetchy/namae.git
synced 2025-03-18 13:00:33 +09:00
17 lines
479 B
JavaScript
17 lines
479 B
JavaScript
|
const fetch = require('isomorphic-unfetch')
|
||
|
|
||
|
async function getGitHubAvailability(name) {
|
||
|
const githubURL = 'https://github.com'
|
||
|
const response = await fetch(`${githubURL}/${encodeURIComponent(name)}`)
|
||
|
return response.status === 404
|
||
|
}
|
||
|
|
||
|
module.exports = async (req, res) => {
|
||
|
const name = req.query.name
|
||
|
if (!name) {
|
||
|
return res.status(400).json({ error: 'no query given' })
|
||
|
}
|
||
|
const availability = await getGitHubAvailability(name)
|
||
|
res.json({ availability })
|
||
|
}
|