fix(admin-web): proxy routes forward body on DELETE — use method !== GET/HEAD guard

This commit is contained in:
saravanakumardb1 2026-03-21 18:18:26 -07:00
parent e712113c30
commit b6f9636171
15 changed files with 15 additions and 15 deletions

View File

@ -22,7 +22,7 @@ async function proxy(req: NextRequest, { params }: { params: Promise<{ path: str
'x-product-id': req.headers.get('x-product-id') || process.env.PRODUCT_ID || 'lysnrai',
};
const fetchOptions: RequestInit = { method: req.method, headers };
if (['POST', 'PUT', 'PATCH'].includes(req.method)) fetchOptions.body = await req.text();
if (req.method !== 'GET' && req.method !== 'HEAD') fetchOptions.body = await req.text();
const res = await fetch(`${PLATFORM_URL}${targetPath}${qs}`, fetchOptions);
const data = await res.json().catch(() => null);
return NextResponse.json(data ?? { error: res.statusText }, { status: res.status });

View File

@ -29,7 +29,7 @@ async function proxy(req: NextRequest, { params }: { params: Promise<{ path: str
};
const fetchOptions: RequestInit = { method: req.method, headers };
if (['POST', 'PUT', 'PATCH'].includes(req.method)) {
if (req.method !== 'GET' && req.method !== 'HEAD') {
fetchOptions.body = await req.text();
}

View File

@ -22,7 +22,7 @@ async function proxy(req: NextRequest, { params }: { params: Promise<{ path: str
'x-product-id': req.headers.get('x-product-id') || process.env.PRODUCT_ID || 'lysnrai',
};
const fetchOptions: RequestInit = { method: req.method, headers };
if (['POST', 'PUT', 'PATCH'].includes(req.method)) fetchOptions.body = await req.text();
if (req.method !== 'GET' && req.method !== 'HEAD') fetchOptions.body = await req.text();
const res = await fetch(`${PLATFORM_URL}${targetPath}${qs}`, fetchOptions);
const data = await res.json().catch(() => null);
return NextResponse.json(data ?? { error: res.statusText }, { status: res.status });

View File

@ -22,7 +22,7 @@ async function proxy(req: NextRequest, { params }: { params: Promise<{ path: str
'x-product-id': req.headers.get('x-product-id') || process.env.PRODUCT_ID || 'lysnrai',
};
const fetchOptions: RequestInit = { method: req.method, headers };
if (['POST', 'PUT', 'PATCH'].includes(req.method)) fetchOptions.body = await req.text();
if (req.method !== 'GET' && req.method !== 'HEAD') fetchOptions.body = await req.text();
const res = await fetch(`${PLATFORM_URL}${targetPath}${qs}`, fetchOptions);
const data = await res.json().catch(() => null);
return NextResponse.json(data ?? { error: res.statusText }, { status: res.status });

View File

@ -22,7 +22,7 @@ async function proxy(req: NextRequest, { params }: { params: Promise<{ path: str
'x-product-id': req.headers.get('x-product-id') || process.env.PRODUCT_ID || 'lysnrai',
};
const fetchOptions: RequestInit = { method: req.method, headers };
if (['POST', 'PUT', 'PATCH'].includes(req.method)) fetchOptions.body = await req.text();
if (req.method !== 'GET' && req.method !== 'HEAD') fetchOptions.body = await req.text();
const res = await fetch(`${PLATFORM_URL}${targetPath}${qs}`, fetchOptions);
const data = await res.json().catch(() => null);
return NextResponse.json(data ?? { error: res.statusText }, { status: res.status });

View File

@ -22,7 +22,7 @@ async function proxy(req: NextRequest, { params }: { params: Promise<{ path: str
'x-product-id': req.headers.get('x-product-id') || process.env.PRODUCT_ID || 'lysnrai',
};
const fetchOptions: RequestInit = { method: req.method, headers };
if (['POST', 'PUT', 'PATCH'].includes(req.method)) fetchOptions.body = await req.text();
if (req.method !== 'GET' && req.method !== 'HEAD') fetchOptions.body = await req.text();
const res = await fetch(`${PLATFORM_URL}${targetPath}${qs}`, fetchOptions);
const data = await res.json().catch(() => null);
return NextResponse.json(data ?? { error: res.statusText }, { status: res.status });

View File

@ -22,7 +22,7 @@ async function proxy(req: NextRequest, { params }: { params: Promise<{ path: str
'x-product-id': req.headers.get('x-product-id') || process.env.PRODUCT_ID || 'lysnrai',
};
const fetchOptions: RequestInit = { method: req.method, headers };
if (['POST', 'PUT', 'PATCH'].includes(req.method)) fetchOptions.body = await req.text();
if (req.method !== 'GET' && req.method !== 'HEAD') fetchOptions.body = await req.text();
const res = await fetch(`${PLATFORM_URL}${targetPath}${qs}`, fetchOptions);
const data = await res.json().catch(() => null);
return NextResponse.json(data ?? { error: res.statusText }, { status: res.status });

View File

@ -22,7 +22,7 @@ async function proxy(req: NextRequest, { params }: { params: Promise<{ path: str
'x-product-id': req.headers.get('x-product-id') || process.env.PRODUCT_ID || 'lysnrai',
};
const fetchOptions: RequestInit = { method: req.method, headers };
if (['POST', 'PUT', 'PATCH'].includes(req.method)) fetchOptions.body = await req.text();
if (req.method !== 'GET' && req.method !== 'HEAD') fetchOptions.body = await req.text();
const res = await fetch(`${PLATFORM_URL}${targetPath}${qs}`, fetchOptions);
const data = await res.json().catch(() => null);
return NextResponse.json(data ?? { error: res.statusText }, { status: res.status });

View File

@ -22,7 +22,7 @@ async function proxy(req: NextRequest, { params }: { params: Promise<{ path: str
'x-product-id': req.headers.get('x-product-id') || process.env.PRODUCT_ID || 'lysnrai',
};
const fetchOptions: RequestInit = { method: req.method, headers };
if (['POST', 'PUT', 'PATCH'].includes(req.method)) fetchOptions.body = await req.text();
if (req.method !== 'GET' && req.method !== 'HEAD') fetchOptions.body = await req.text();
const res = await fetch(`${PLATFORM_URL}${targetPath}${qs}`, fetchOptions);
const data = await res.json().catch(() => null);
return NextResponse.json(data ?? { error: res.statusText }, { status: res.status });

View File

@ -29,7 +29,7 @@ async function proxy(req: NextRequest, { params }: { params: Promise<{ path: str
};
const fetchOptions: RequestInit = { method: req.method, headers };
if (['POST', 'PUT', 'PATCH'].includes(req.method)) {
if (req.method !== 'GET' && req.method !== 'HEAD') {
fetchOptions.body = await req.text();
}

View File

@ -22,7 +22,7 @@ async function proxy(req: NextRequest, { params }: { params: Promise<{ path: str
'x-product-id': req.headers.get('x-product-id') || process.env.PRODUCT_ID || 'lysnrai',
};
const fetchOptions: RequestInit = { method: req.method, headers };
if (['POST', 'PUT', 'PATCH'].includes(req.method)) fetchOptions.body = await req.text();
if (req.method !== 'GET' && req.method !== 'HEAD') fetchOptions.body = await req.text();
const res = await fetch(`${PLATFORM_URL}${targetPath}${qs}`, fetchOptions);
const data = await res.json().catch(() => null);
return NextResponse.json(data ?? { error: res.statusText }, { status: res.status });

View File

@ -22,7 +22,7 @@ async function proxy(req: NextRequest, { params }: { params: Promise<{ path: str
'x-product-id': req.headers.get('x-product-id') || process.env.PRODUCT_ID || 'lysnrai',
};
const fetchOptions: RequestInit = { method: req.method, headers };
if (['POST', 'PUT', 'PATCH'].includes(req.method)) fetchOptions.body = await req.text();
if (req.method !== 'GET' && req.method !== 'HEAD') fetchOptions.body = await req.text();
const res = await fetch(`${PLATFORM_URL}${targetPath}${qs}`, fetchOptions);
const data = await res.json().catch(() => null);
return NextResponse.json(data ?? { error: res.statusText }, { status: res.status });

View File

@ -29,7 +29,7 @@ async function proxy(req: NextRequest, { params }: { params: Promise<{ path: str
};
const fetchOptions: RequestInit = { method: req.method, headers };
if (['POST', 'PUT', 'PATCH'].includes(req.method)) {
if (req.method !== 'GET' && req.method !== 'HEAD') {
fetchOptions.body = await req.text();
}

View File

@ -29,7 +29,7 @@ async function proxy(req: NextRequest, { params }: { params: Promise<{ path: str
};
const fetchOptions: RequestInit = { method: req.method, headers };
if (['POST', 'PUT', 'PATCH'].includes(req.method)) {
if (req.method !== 'GET' && req.method !== 'HEAD') {
fetchOptions.body = await req.text();
}

View File

@ -22,7 +22,7 @@ async function proxy(req: NextRequest, { params }: { params: Promise<{ path: str
'x-product-id': req.headers.get('x-product-id') || process.env.PRODUCT_ID || 'lysnrai',
};
const fetchOptions: RequestInit = { method: req.method, headers };
if (['POST', 'PUT', 'PATCH'].includes(req.method)) fetchOptions.body = await req.text();
if (req.method !== 'GET' && req.method !== 'HEAD') fetchOptions.body = await req.text();
const res = await fetch(`${PLATFORM_URL}${targetPath}${qs}`, fetchOptions);
const data = await res.json().catch(() => null);
return NextResponse.json(data ?? { error: res.statusText }, { status: res.status });