Created
November 4, 2013 05:13
-
-
Save chilts/7298324 to your computer and use it in GitHub Desktop.
Alternative proposal ... not backwards compatible
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 http = require('http') | |
var paramify = require('paramify') | |
var router = paramify() | |
router.get('intro/:greeting', intro) | |
router.get('showtimes/:start/:end', showtimes) | |
router.default(notFound); | |
http.createServer(router).listen(1337, '127.0.0.1') | |
function intro(params, req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}) | |
res.end('Greeting was "' + params.greeting + '"\n') | |
} | |
function showtimes(params, req, res) { | |
res.writeHead(200, {'Content-Type': 'text/plain'}) | |
var message = [ | |
'Show starts at', params.start, | |
'and ends at', params.end | |
].join(' ') + '\n' | |
res.end(message) | |
} | |
function notFound(params, req, res) { | |
// ...etc... | |
} | |
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
I guess change .get() to .match() too.