Skip to content

Instantly share code, notes, and snippets.

@demosifter
Last active July 24, 2017 10:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save demosifter/57089677bd57865fe22675dc269f6ba2 to your computer and use it in GitHub Desktop.
Save demosifter/57089677bd57865fe22675dc269f6ba2 to your computer and use it in GitHub Desktop.
const dns = require('dns');
const pify = require('pify');
//...
module.exports = function (got) {
const inData = got.in.data;
console.log('edig: simple.js: data received:', inData);
return inData.map(d => {
const req = JSON.parse(d.value);
console.log(`${req.method}: ${req.request_uri}`);
const domain = req.request_uri.replace('/edig/txt/', '');
const respond = (c, b) => ({
name: 'api_rpc',
key: d.key,
value: newResponse(c, {'Content-Type': ['text/plain; charset=utf-8']}, b)
});
return pify(dns).resolve(domain, 'TXT')
.then(addr =>{
const linePattern = r => `${domain}.\t\tIN\tTXT\t'${r.join(' ')}'`;
return respond(200, addr.map(linePattern).join('\n'))
})
.catch(e => respond(500, e))
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment