Thursday, 8 August 2013

Change response body before outputting in node.js

Change response body before outputting in node.js

I'm new to Node.js. I'm tryinbg to build a small server acting as proxy
for a POST call to a opendata service, then doing some stuff, binding to a
presentation layer, finally outputting to browser.
Here's the code:
dispatcher.onGet("/metro", function(req, res) {
var r = request({body: '<?xml version="1.0" encoding="ISO-8859-1"
?><poirequest><poi_id>87087</poi_id><lng>0</lng></poirequest>'},
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log('Public transformation public API called');
}
}).pipe(res);
res.on('finish', function() {
console.log('Request completed;');
});
});
http.createServer(function (req, res) {
dispatcher.dispatch(req, res);
}).listen(1337, '0.0.0.0');
console.log('Server is listening');
The dispatcher is the simplest i found on mpm:
https://npmjs.org/package/httpdispatcher The question is: how can I alter
(basically, html-code stripping) the response body before outputting to
the output pipe?

No comments:

Post a Comment