Created
February 9, 2012 21:57
-
-
Save DTrejo/1783626 to your computer and use it in GitHub Desktop.
notfound not called
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') | |
, director = require('director') | |
, PORT = process.env.port || 8000 | |
var routes = { | |
'/hello': { | |
get: function(route) { this.res.end('/hello') } | |
} | |
} | |
var routerOptions = { notfound: notFound } | |
var router = new director.http.Router(routes).configure(routerOptions) | |
var server = http.createServer(function(req, res) { | |
router.dispatch(req, res) | |
}) | |
// strangely, this does not work: | |
// http.createServer(router.dispatch) | |
// called when no route matches, like for static files! | |
function notFound(req, res) { | |
console.log('notFound entered!'); | |
req.end('yay, notFound was called!') | |
} | |
server.listen(PORT) | |
console.log('Listening on http://localhost:'+PORT) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
solution: