2019-07-31 02:08:41 +09:00
|
|
|
import whois from 'whois-json'
|
2019-08-01 13:22:03 +09:00
|
|
|
const { send, sendError } = require('../util/http')
|
2019-07-31 02:08:41 +09:00
|
|
|
|
|
|
|
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 whois(name, { follow: 3, verbose: true })
|
|
|
|
const availability = response[0].data.domainName ? false : true
|
2019-08-01 13:22:03 +09:00
|
|
|
send(res, availability)
|
2019-07-31 02:08:41 +09:00
|
|
|
} catch (err) {
|
2019-08-01 13:22:03 +09:00
|
|
|
sendError(res, err)
|
2019-07-31 02:08:41 +09:00
|
|
|
}
|
|
|
|
}
|