From 4afbccbb02be7dd1ed03b6d4df568df844b9d652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BF=A0=20/=20green?= Date: Wed, 21 Jun 2023 17:14:27 +0900 Subject: [PATCH] fix(proxy): forward SSE close event (#13578) --- packages/vite/src/node/server/middlewares/proxy.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/vite/src/node/server/middlewares/proxy.ts b/packages/vite/src/node/server/middlewares/proxy.ts index ae289a8f8e9776..6b282e0afea05b 100644 --- a/packages/vite/src/node/server/middlewares/proxy.ts +++ b/packages/vite/src/node/server/middlewares/proxy.ts @@ -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 }] })