-
-
Save hemanth/3070553 to your computer and use it in GitHub Desktop.
This file contains hidden or 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'), | |
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