mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 10:21:36 +03:00
8ad951d7f3
refs #9942 * Added new middleware to trigger events * Refactored webhooks service - added new trigger service, moved listen service to its own file - started listening to new site.changed event - cleaned up trigger service to work with new webhook fields - cleaned up tests - removed redundant trigger method in v0.1 controller
14 lines
379 B
JavaScript
14 lines
379 B
JavaScript
const common = require('../../../lib/common');
|
|
const INVALIDATE_ALL = '/*';
|
|
|
|
module.exports = function emitEvents(req, res, next) {
|
|
res.on('finish', function triggerEvents() {
|
|
if (res.get('X-Cache-Invalidate') === INVALIDATE_ALL) {
|
|
common.events.emit('site.changed');
|
|
}
|
|
|
|
res.removeListener('finish', triggerEvents);
|
|
});
|
|
next();
|
|
};
|