Skip to content

Instantly share code, notes, and snippets.

@tejpratap46
Created June 15, 2017 13:22
Show Gist options
  • Save tejpratap46/9fb60506336f2c78aba408283f178c99 to your computer and use it in GitHub Desktop.
Save tejpratap46/9fb60506336f2c78aba408283f178c99 to your computer and use it in GitHub Desktop.
A simple proxy microservice
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