proxy-backend support sse connections closing
Signed-off-by: Nina Berg <nikb100@gmail.com>
This commit is contained in:
@@ -214,8 +214,12 @@ export function buildMiddleware(
|
||||
].map(h => h.toLocaleLowerCase()),
|
||||
);
|
||||
|
||||
// only forward the allowed headers in backend->client
|
||||
fullConfig.onProxyRes = (proxyRes: http.IncomingMessage) => {
|
||||
fullConfig.onProxyRes = (
|
||||
proxyRes: http.IncomingMessage,
|
||||
_,
|
||||
res: express.Response,
|
||||
) => {
|
||||
// only forward the allowed headers in backend->client
|
||||
const headerNames = Object.keys(proxyRes.headers);
|
||||
|
||||
headerNames.forEach(h => {
|
||||
@@ -223,6 +227,14 @@ export function buildMiddleware(
|
||||
delete proxyRes.headers[h];
|
||||
}
|
||||
});
|
||||
|
||||
// handle SSE connections closed by the backend
|
||||
// https://github.com/chimurai/http-proxy-middleware/discussions/765
|
||||
proxyRes.on('close', () => {
|
||||
if (!res.writableEnded) {
|
||||
res.end();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (reviveConsumedRequestBodies) {
|
||||
|
||||
Reference in New Issue
Block a user