Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let domain = req.query.domain;
if (!domain) {
res.status(400).send("{'Error': 'Please send a domain!'}");
return;
}
const whois = require('whois');
let whoisObject = {
'server': '', // this can be a string ('host:port') or an object with host and port as its keys; leaving it empty makes lookup rely on servers.json
'follow': 2, // number of times to follow redirects
'timeout': 0, // socket timeout, excluding this doesn't override any default timeout value
'verbose': false, // setting this to true returns an array of responses from all servers
};
whois.lookup(domain, whoisObject, function(err, data) {
if (!err) {
let myEscapedJSONString = data.replace(/[\\]/g, '\\\\')
.replace(/[\"]/g, '\\\"')
.replace(/[\/]/g, '\\/')
.replace(/[\b]/g, '\\b')
.replace(/[\f]/g, '\\f')
.replace(/[\n]/g, '\\n')
.replace(/[\r]/g, '\\r')
.replace(/[\t]/g, '\\t');
res.status(200).json({'result': myEscapedJSONString});
} else {
res.status(500).send(err);
}
});
});