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:
@@ -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 = {}
|
||||
|
||||
Reference in New Issue
Block a user