Skip to content

Commit

Permalink
Merge pull request #12 from vagusX/fix/events-stack
Browse files Browse the repository at this point in the history
fix: register events only once
  • Loading branch information
vagusX committed Aug 29, 2017
2 parents 1676450 + f2a307e commit e1a57d0
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ const route = pathMatch({
end: false
})

let eventRegistered = false

/**
* Koa Http Proxy Middleware
*/
Expand Down Expand Up @@ -50,10 +52,11 @@ module.exports = (context, options) => (ctx, next) => {

if (logs) logger(ctx, opts.target)

if (events && typeof events === 'object') {
if (events && typeof events === 'object' && !eventRegistered) {
Object.entries(events).forEach(([event, handler]) => {
proxy.on(event, handler)
})
eventRegistered = true
}

proxy.web(ctx.req, ctx.res, httpProxyOpts, e => {
Expand Down

0 comments on commit e1a57d0

Please sign in to comment.