From fe8a06591bd42eb6fc425ac1e3c0593dbede0716 Mon Sep 17 00:00:00 2001 From: ekko Date: Sat, 11 Apr 2026 16:19:52 +0800 Subject: [PATCH] fix: read request body before forwarding in API proxy Node.js fetch requires duplex option when streaming request body. Read body chunks first, then forward as Buffer. Co-Authored-By: Claude Opus 4.6 --- bin/hermes-web-ui.mjs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/bin/hermes-web-ui.mjs b/bin/hermes-web-ui.mjs index 2600b8d..2cfa35e 100755 --- a/bin/hermes-web-ui.mjs +++ b/bin/hermes-web-ui.mjs @@ -57,10 +57,16 @@ async function proxyRequest(req, res, reqPath) { delete headers['referer'] try { + const hasBody = req.method !== 'GET' && req.method !== 'HEAD' + const bodyChunks = hasBody ? [] : null + if (hasBody) { + for await (const chunk of req) bodyChunks.push(chunk) + } + const apiRes = await fetch(url, { method: req.method, headers, - body: req.method !== 'GET' && req.method !== 'HEAD' ? req : undefined, + body: bodyChunks ? Buffer.concat(bodyChunks) : undefined, }) const resHeaders = {}