Merge pull request #3787 from RaenonX/master
Some checks are pending
Node.js CI / build (postgresql, 18.18, 10) (push) Waiting to run

Fixed `/api/batch` request recreation failure
This commit is contained in:
Mike Cao 2025-11-25 16:08:02 -08:00 committed by GitHub
commit dcc1ae1864
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,7 +18,20 @@ export async function POST(request: Request) {
let index = 0;
for (const data of body) {
const newRequest = new Request(request, { body: JSON.stringify(data) });
// Recreate a fresh Request since `new Request(request)` will have the following error:
// > Cannot read private member #state from an object whose class did not declare it
// Copy headers we received, ensure JSON content type, and avoid conflicting content-length
const headers = new Headers(request.headers);
headers.set('content-type', 'application/json');
headers.delete('content-length');
const newRequest = new Request(request.url, {
method: 'POST',
headers,
body: JSON.stringify(data),
});
const response = await send.POST(newRequest);
if (!response.ok) {