Ghost/core/server/web/shared/middlewares/emit-events.js
Rishabh Garg 8ad951d7f3
Added new site.changed event and webhook trigger service (#10019)
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
2018-10-19 00:01:30 +05:30

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();
};