|
|
|
@ -110,6 +110,9 @@ module.exports = function (Plugins) {
|
|
|
|
|
case 'static':
|
|
|
|
|
fireStaticHook(hook, hookList, params, done);
|
|
|
|
|
break;
|
|
|
|
|
case 'response':
|
|
|
|
|
fireResponseHook(hook, hookList, params, done);
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
winston.warn('[plugins] Unknown hookType: ' + hookType + ', hook : ' + hook);
|
|
|
|
|
callback();
|
|
|
|
@ -184,6 +187,28 @@ module.exports = function (Plugins) {
|
|
|
|
|
}, callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function fireResponseHook(hook, hookList, params, callback) {
|
|
|
|
|
if (!Array.isArray(hookList) || !hookList.length) {
|
|
|
|
|
return callback();
|
|
|
|
|
}
|
|
|
|
|
async.eachSeries(hookList, function (hookObj, next) {
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Skip remaining hooks if headers have been sent
|
|
|
|
|
if (params.res.headersSent) {
|
|
|
|
|
return next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
hookObj.method(params);
|
|
|
|
|
next();
|
|
|
|
|
}, callback);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Plugins.hasListeners = function (hook) {
|
|
|
|
|
return !!(Plugins.loadedHooks[hook] && Plugins.loadedHooks[hook].length > 0);
|
|
|
|
|
};
|
|
|
|
|