Created
May 22, 2013 06:56
-
-
Save jdpaton/5625726 to your computer and use it in GitHub Desktop.
Simply return any custom HTTP code by supplying the url param ?code=302
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
var url = require('url'); | |
var http = require('http'); | |
var querystring = require('querystring'); | |
// Example usage: curl -I http://localhost:1337/?code=500 | |
http.createServer(function (req, res) { | |
var purl = url.parse(req.url).query; | |
var qs = querystring.parse(purl); | |
var status_code = qs.code || 200; | |
res.writeHead(status_code, {'Content-Type': 'text/plain'}); | |
res.end('Hello Status code: ' + status_code + '\n'); | |
}).listen(process.env.PORT || 1337); | |
console.log('Server running at http://127.0.0.1:1337/'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment