debug: clone req body voor POST pins + verbose logging
This commit is contained in:
@@ -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) {
|
||||||
|
|||||||
Reference in New Issue
Block a user