Last active
July 24, 2017 10:28
-
-
Save demosifter/57089677bd57865fe22675dc269f6ba2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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