Created
July 17, 2013 21:38
-
-
Save andrewwho/6024780 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
var connect = require('connect'); | |
var querystring = require('querystring'); | |
var utils = require('util'); | |
connect.createServer( | |
connect.static(__dirname) | |
).use(function(req, res){ | |
if (req.method == 'POST') { | |
console.log("[200] " + req.method + " to " + req.url); | |
var fullBody = ''; | |
req.on('data', function(chunk) { | |
// append the current chunk of data to the fullBody variable | |
fullBody += chunk.toString(); | |
}); | |
req.on('end', function() { | |
// request ended -> do something with the data | |
res.writeHead(200, "OK", {'Content-Type': 'text/html'}); | |
// parse the received body data | |
var decodedBody = querystring.parse(fullBody); | |
// output the decoded data to the HTTP response | |
res.write('<html><head><title>Post data</title></head><body><pre>'); | |
res.write(utils.inspect(decodedBody)); | |
res.write('</pre></body></html>'); | |
console.log('fdsfs'); | |
res.end(); | |
}); | |
} else { | |
console.log("[405] " + req.method + " to " + req.url); | |
res.writeHead(405, "Method not supported", {'Content-Type': 'text/html'}); | |
res.end('<html><head><title>405 - Method not supported</title></head><body><h1>Method not supported.</h1></body></html>'); | |
} | |
}).listen(1337); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment