fix(proxy): re-stream express.json()-consumed body to remote nodes for POST/PUT/PATCH

express.json() fully drains the incoming request stream. http-proxy-middleware then
pipes an already-consumed empty stream to the remote Sencho instance, which holds the
connection open waiting for body bytes that never arrive (Content-Length says N but 0
bytes are forwarded). This caused all POST/PUT/PATCH requests to remote nodes — most
visibly 'Add Alert Rule' — to hang indefinitely with an infinite loading spinner.

Fix: in the proxyReq handler, write JSON.stringify(req.body) with correct Content-Type
and Content-Length headers before forwarding, restoring the full request body.
This commit is contained in:
SaelixCode
2026-03-21 01:26:12 -04:00
parent e190f3ad8a
commit a703707aa0
2 changed files with 13 additions and 0 deletions
+12
View File
@@ -370,6 +370,18 @@ const remoteNodeProxy = createProxyMiddleware<Request, Response>({
const newQs = params.toString();
proxyReq.path = pathname + (newQs ? `?${newQs}` : '');
}
// Re-stream the request body for POST/PUT/PATCH requests.
// express.json() fully drains the incoming stream and stores the parsed
// object in req.body. http-proxy-middleware then pipes an already-consumed
// stream to the remote, which causes the remote server to stall waiting for
// body bytes that never arrive (the Content-Length header says N bytes but
// 0 are forwarded), hanging the request indefinitely.
if (req.body && Object.keys(req.body).length > 0) {
const bodyData = JSON.stringify(req.body);
proxyReq.setHeader('Content-Type', 'application/json');
proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData));
proxyReq.write(bodyData);
}
},
error: (err, _req, proxyRes) => {
console.error('[Proxy] Remote node error:', (err as Error).message);