我正在使用护照登录.我想要除了'/'要求登录之外的所有路线.
我有一个
ensureAuthenticated
Run Code Online (Sandbox Code Playgroud)
功能,检查我是否经过身份验证.
我宁愿不想把中间件调用放到每个路由中:
app.get('/first', ensureAuthenticated,...)
app.get('/second', ensureAuthenticated,...)
Run Code Online (Sandbox Code Playgroud)
有没有办法分配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', ...);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1509 次 |
| 最近记录: |