您可以在Express链中插入“全部捕获”中间件作为最后一个中间件/路由:
//configure the order of operations for request handlers:app.configure(function(){ app.use(express.logger('dev')); app.use(express.bodyParser()); app.use(express.cookieParser()); app.use(express.static(__dirname+'/assets')); // try to serve static files app.use(app.router); // try to match req with a route app.use(redirectUnmatched); // redirect if nothing else sent a response});function redirectUnmatched(req, res) { res.redirect("http://www.mysite.com/");}...// your routesapp.get('/', function(req, res) { ... });...// start listeningapp.listen(3000);我使用这样的设置来生成自定义
404 Not Found页面。



