Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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