Skip to content

Instantly share code, notes, and snippets.

@lerouxb
Created November 29, 2010 15:07
Show Gist options
  • Save lerouxb/720050 to your computer and use it in GitHub Desktop.
Save lerouxb/720050 to your computer and use it in GitHub Desktop.
Log all posted variables via a little nodejs server.
var http = require('http'),
querystring = require('querystring')
var PORT = 8124;
http.createServer(function(req, res) {
if (req.method == 'POST') {
req.rawpostdata = '';
req.addListener('data', function(chunk) {
req.rawpostdata += chunk.toString('ascii'); // I hope
});
req.addListener('end', function() {
req.formdata = querystring.parse(req.rawpostdata);
var body = '====================\n';
for (var k in req.formdata) {
body += k+'='+req.formdata[k]+'\n';
}
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end(body);
console.log(body);
});
} else {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Not a POST request.');
}
}).listen(PORT);
console.log('Server running at http://127.0.0.1:/'+PORT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment