Skip to content

Commit

Permalink
fix(proxy): forward SSE close event (#13578)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red committed Jun 21, 2023
1 parent a376a43 commit 4afbccb
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/vite/src/node/server/middlewares/proxy.ts
Expand Up @@ -91,6 +91,17 @@ export function proxyMiddleware(
})
})

// https://github.com/http-party/node-http-proxy/issues/1520#issue-877626125
// https://github.com/chimurai/http-proxy-middleware/blob/cd58f962aec22c925b7df5140502978da8f87d5f/src/plugins/default/debug-proxy-errors-plugin.ts#L25-L37
proxy.on('proxyRes', (proxyRes, req, res) => {
res.on('close', () => {
if (!res.writableEnded) {
debug?.('destroying proxyRes in proxyRes close event')
proxyRes.destroy()
}
})
})

// clone before saving because http-proxy mutates the options
proxies[context] = [proxy, { ...opts }]
})
Expand Down

0 comments on commit 4afbccb

Please sign in to comment.