我会将checkUser中间件添加到我的除首页之外的所有路径中。
app.get('/', routes.index);app.get('/account', checkUser, routes.account);要么
app.all('*', checkUser);function checkUser(req, res, next) { if ( req.path == '/') return next(); //authenticate user next();}您可以使用下划线扩展它,以在未经身份验证的路径数组中搜索req.path:
function checkUser(req, res, next) { var _ = require('underscore') , nonSecurePaths = ['/', '/about', '/contact']; if ( _.contains(nonSecurePaths, req.path) ) return next(); //authenticate user next();}


