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 <noreply@anthropic.com>
This commit is contained in:
ekko
2026-04-11 16:19:52 +08:00
parent 7ea54efb01
commit fe8a06591b
+7 -1
View File
@@ -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 = {}