Skip to content

Instantly share code, notes, and snippets.

@chilts
Created November 4, 2013 05:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chilts/7298324 to your computer and use it in GitHub Desktop.
Save chilts/7298324 to your computer and use it in GitHub Desktop.
Alternative proposal ... not backwards compatible
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/')
@chilts
Copy link
Author

chilts commented Nov 4, 2013

I guess change .get() to .match() too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment