我的routes.js文件
module.exports = function(app) {
//donesn't need to be authorized
app.use('/login', require('./controllers/session'))
//will need to be protected
app.use('/user', auth, require('./controllers/users'))
app.use('/vineyards', auth, require('./controllers/vineyard'))
app.use('/varietals', require('./controllers/varietals'))
app.use('/wines', auth, require('./controllers/wine'))
app.use('/spectrums', auth, require('./controllers/spectrum'))
app.use('/lockers', auth, require('./controllers/locker'))
app.use('/logout', auth, require('./controllers/session'))
}
' auth'中间件在我发出get或jsonp请求时起作用,但如果我使用postc错误输出,statusCode为0,并且内容' XMLHttpRequestProgressEvent XMLHttpRequestProgressEvent'。但是,如果我进入实际的控制器并将auth中间件放在如下的实际帖子上,它就可以工作。
router.post('/', auth, function(req, res) {});
为什么?是否有更好的方法使中间件在所有调用控制器之前运行,然后将其放在每个单独的路径上?