Skip to content

Commit 4afbccb

Browse files
authoredJun 21, 2023
fix(proxy): forward SSE close event (#13578)
1 parent a376a43 commit 4afbccb

File tree

1 file changed

+11
-0
lines changed
  • packages/vite/src/node/server/middlewares

1 file changed

+11
-0
lines changed
 

‎packages/vite/src/node/server/middlewares/proxy.ts

+11
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ export function proxyMiddleware(
9191
})
9292
})
9393

94+
// https://github.com/http-party/node-http-proxy/issues/1520#issue-877626125
95+
// https://github.com/chimurai/http-proxy-middleware/blob/cd58f962aec22c925b7df5140502978da8f87d5f/src/plugins/default/debug-proxy-errors-plugin.ts#L25-L37
96+
proxy.on('proxyRes', (proxyRes, req, res) => {
97+
res.on('close', () => {
98+
if (!res.writableEnded) {
99+
debug?.('destroying proxyRes in proxyRes close event')
100+
proxyRes.destroy()
101+
}
102+
})
103+
})
104+
94105
// clone before saving because http-proxy mutates the options
95106
proxies[context] = [proxy, { ...opts }]
96107
})

0 commit comments

Comments
 (0)