Skip to content

Instantly share code, notes, and snippets.

@hemanth
Forked from tbergeron/gist:3067172
Created July 8, 2012 11:05
Show Gist options
  • Save hemanth/3070553 to your computer and use it in GitHub Desktop.
Save hemanth/3070553 to your computer and use it in GitHub Desktop.
var http = require('http'),
router = new require('routes').Router();
// route response function
var test = function(req, res, params, splats) {
// everything is undefined here... wtf?
console.log(req);
console.log(res);
console.log(params);
console.log(splats);
};
// routes
router.addRoute("/test/:name?", test);
// server
http.createServer(function(req, res) {
// matching a route
var route = router.match(req.url);
// if one is matched, executing the reponse function
if (route) {
route.fn.apply(req, res, route.params, route.splats);
}
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello World\n');
}).listen(3000, '127.0.0.1');
console.log('Server running at http://127.0.0.1:3000/');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment