Last active
November 6, 2015 10:37
-
-
Save D-32/cfd277b010b3c5361420 to your computer and use it in GitHub Desktop.
Simple node server to debug stuff
This file contains 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
http = require('http'); | |
fs = require('fs'); | |
url = require('url'); | |
server = http.createServer( function(req, res) { | |
console.log(req.url) | |
if (req.method == 'POST') { | |
var body = ''; | |
req.on('data', function (data) { | |
body += data; | |
}); | |
req.on('end', function () { | |
console.log("POST: " + unescape(body)); | |
}); | |
res.writeHead(200, {'Content-Type': 'text/html'}); | |
res.end('Hello POST!'); | |
} else { | |
var url_parts = url.parse(req.url, true); | |
var query = url_parts.query; | |
console.log("GET: " + JSON.stringify(query)); | |
res.writeHead(200, {'Content-Type': 'text/html'}); | |
res.end("Hello GET!"); | |
} | |
console.log("-------"); | |
}); | |
server.listen(8000); | |
console.log("Server running at http://127.0.0.1:8000/"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment