Ghost/core/server/web/parent/middleware/emit-events.js
Hannah Wolfe 61e1b19d46
Added comments to all usages of lib/common/events
- This is a precursor to trying to split apart into:
   - model events + webhooks system which makes sense
   - frontend events which should be independent or removed
   - maybe some concept of a settings manager that we can use in various places to bind logic 🤔
   - other usages of events that should be refactored to not use events
2021-07-07 16:02:44 +01:00

16 lines
452 B
JavaScript

const INVALIDATE_ALL = '/*';
// Emit the site.changed event, a special model event used for webhooks
const events = require('../../../lib/common/events');
module.exports = function emitEvents(req, res, next) {
res.on('finish', function triggerEvents() {
if (res.get('X-Cache-Invalidate') === INVALIDATE_ALL) {
events.emit('site.changed');
}
res.removeListener('finish', triggerEvents);
});
next();
};