Created
February 14, 2015 18:20
-
-
Save RX14/f916a49834a9347b40f3 to your computer and use it in GitHub Desktop.
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
console.log('Loading event'); | |
var url = require("url"); | |
var http = require("http"); | |
exports.handler = function(event, context) { | |
var body = JSON.stringify(event.body); | |
event.handlers.forEach(function(handler) { | |
var thisURL = url.parse(handler.url); | |
var options = { | |
hostname: thisURL.hostname, | |
port: thisURL.port || 80, | |
path: thisURL.path, | |
method: handler.method, | |
headers: { | |
'Content-Type': 'application/json', | |
'Content-Length': body.length | |
} | |
}; | |
var req = http.request(options, function(res) { | |
console.log("STATUS: " + res.statusCode); | |
res.setEncoding("utf8"); | |
res.on("end", function() { | |
console.log("FINISH"); | |
}); | |
res.resume(); | |
}); | |
req.on('error', function(e) { | |
console.log('ERROR: ' + e.message); | |
}); | |
req.write(body); | |
req.end(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment