我正在使用护照登录。
我想要除 '/'
之外的所有路由都需要登录。
我有一个
ensureAuthenticated
函数,用于检查我是否已通过身份验证。
我不想将中间件调用放入每个路由中:
app.get('/first', ensureAuthenticated,...)
app.get('/second', ensureAuthenticated,...)
有没有办法将 ensureAuthenticated
分配给除 '/'
之外的所有路由?
最佳答案
您可以使用app.all
为此:
// regular route
app.get('/', ...);
// make sure all following routes will be passed through ensureAuthenticated
app.all('*', ensureAuthenticated);
app.get('/first', ...);
app.get('/second', ...);
关于node.js - NodeJS路由: all routes with authentication except first page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19395691/