debug: clone req body voor POST pins + verbose logging

This commit is contained in:
maikrolf
2026-09-19 17:39:06 +02:00
parent 5a454a2ddc
commit b7fb7daa4d
+15 -4
View File
@@ -106,11 +106,22 @@ async function handleLocalPins(path: string, method: string, req: NextRequest):
// POST /api/pins — pin een CID // POST /api/pins — pin een CID
if (p === 'pins' && method === 'POST') { if (p === 'pins' && method === 'POST') {
try { try {
// Lees body als text, dan parse als JSON (voorkomt "body already read" issues) // Clone de request om body te lezen (voorkomt "body already consumed")
const text = await req.text(); const clonedReq = req.clone();
const body = text ? JSON.parse(text) : {}; const text = await clonedReq.text();
console.log('[handleLocalPins] POST body:', text);
if (!text) {
return NextResponse.json({ error: 'Empty body' }, { status: 400 });
}
const body = JSON.parse(text);
const { cid, name, size } = body; const { cid, name, size } = body;
if (!cid) return NextResponse.json({ error: 'cid required' }, { status: 400 });
if (!cid) {
return NextResponse.json({ error: 'cid required' }, { status: 400 });
}
await localAddPin(cid, name, size || 0); await localAddPin(cid, name, size || 0);
return NextResponse.json({ cid }); return NextResponse.json({ cid });
} catch (e) { } catch (e) {