I am implementing an IFTTT Action using Node.js. Node.js is version 0.10.29 running on Windows Server 2012 R2.
I am trying to read the body of a POST that is coming from IFTTT. The 'data' event is not firing. Only the 'readable' event is firing. No other events such as 'end' are firing.
However, if I simulate the same POST request using curl, from another server, this code works great.
Also, if I place Fiddler on my server in between IFTTT and my Node.js, it works great.
The request coming from IFTTT looks great in Fiddler, and when Fiddler "processes" it somehow, the Node.js code can read it.
What could be the issue?
var s = http.createServer(process_request);
s.listen(8080);
function process_request(req, res) {
req.parsed_url = url.parse(req.url, true);
var core_url = req.parsed_url.pathname;
if (core_url == '/ifttt/v1/status' && req.method.toLowerCase() == 'get') {
// do stuff required for their test
}
else if (core_url == '/ifttt/v1/test/setup' && req.method.toLowerCase() == 'post') {
// do stuff required for their test
}
else if (core_url == '/ifttt/v1/actions/my_action' && req.method.toLowerCase() == 'post') {
if (<the channel key matches>) {
var json_body = "";
req.on('readable',function () { console.log("In callback for readable ");});
req.on('end', function (data) { console.log("In callback for end: " + json_body); });
req.on('close', function (data) { console.log("In callback for close ");});
req.on('error', function (data) { console.log("In callback for error "); });
req.on('data',
function (chunkdata) {
console.log("In callback for data ");
if (chunkdata) {
if (typeof chunkdata == 'string') { json_body += chunkdata; }
else { console.log("data: No chunkdata "); }
}
};
)
}
} // action url
} // function process_request
Update: I rewrote this code using Express and the problem did not reappear.