Skip to content

Commit

Permalink
fix: unable to register async method as response hook listener
Browse files Browse the repository at this point in the history
Also fixes #8723, /api/config now runs middleware.authenticateOrGuest
  • Loading branch information
julianlam committed Oct 6, 2020
1 parent b01bc2a commit dde5b6b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions src/plugins/hooks.js
Expand Up @@ -189,21 +189,20 @@ module.exports = function (Plugins) {
if (!Array.isArray(hookList) || !hookList.length) {
return;
}
await async.eachSeries(hookList, function (hookObj, next) {
await async.eachSeries(hookList, async (hookObj) => {
if (typeof hookObj.method !== 'function') {
if (global.env === 'development') {
winston.warn('[plugins] Expected method for hook \'' + hook + '\' in plugin \'' + hookObj.id + '\' not found, skipping.');
}
return next();
return;
}

// Skip remaining hooks if headers have been sent
if (params.res.headersSent) {
return next();
return;
}

hookObj.method(params);
next();
await hookObj.method(params);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/routes/api.js
Expand Up @@ -8,7 +8,7 @@ module.exports = function (app, middleware, controllers) {
var router = express.Router();
app.use('/api', router);

router.get('/config', middleware.applyCSRF, controllers.api.getConfig);
router.get('/config', middleware.applyCSRF, middleware.authenticateOrGuest, controllers.api.getConfig);

router.get('/self', controllers.user.getCurrentUser);
router.get('/user/uid/:uid', middleware.canViewUsers, controllers.user.getUserByUID);
Expand Down

0 comments on commit dde5b6b

Please sign in to comment.