Created
June 15, 2017 13:22
-
-
Save tejpratap46/9fb60506336f2c78aba408283f178c99 to your computer and use it in GitHub Desktop.
A simple proxy microservice
This file contains hidden or 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
module.exports = (url = 'world', context, callback) => { | |
var http = require("https"); | |
var req = http.get(url, function (res) { | |
var chunks = []; | |
res.on("data", function (chunk) { | |
chunks.push(chunk); | |
}); | |
res.on("end", function () { | |
var body = Buffer.concat(chunks); | |
try { | |
callback(null, JSON.parse(body.toString())); | |
} catch(e) { | |
callback(null, body); | |
} | |
}); | |
}); | |
req.end(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment