Fixed /api/batch request recreation failure

This commit is contained in:
RaenonX 2025-11-24 08:07:31 +08:00
parent aaa1f9dc58
commit 2b34cbeb37
No known key found for this signature in database
GPG key ID: 27348CBA8F0C90F1

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) {