Turn the middleware into an events emitter for extensibility