Ответ 1
Вы можете вставить промежуточное ПО "уловить все" в качестве последнего промежуточного программного обеспечения/маршрута в цепочке 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 routes
app.get('/', function(req, res) { ... });
...
// start listening
app.listen(3000);
Я использую такую настройку для создания пользовательской страницы 404 Not Found
.