I am having trouble with vercel serverless functions, in that I am getting the following error:
artwork route hit!
error SyntaxError: Unexpected end of JSON input
at JSON.parse ()
at parseJSONFromBytes (node:internal/deps/undici/undici:6571:19)
at successSteps (node:internal/deps/undici/undici:6545:27)
at node:internal/deps/undici/undici:1211:60
at node:internal/process/task_queues:140:7
at AsyncResource.runInAsyncScope (node:async_hooks:203:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
This error occurs at an attempt to call await req.json() within a route handler of a next project (app router, /api folder).
These routes work fine on my local machine, and the request is being sent in the correct format. I have this app deployed as a long running service on another platform, and there are no issues when I route requests there either - This leads me to believe that there is an issue with my vercel setup.
// imports..
export async function POST(req: NextRequest) {
console.log("artwork route hit!"); // this is logged
if (!req.body) {
console.log("no body found") // this is not logged
return new NextResponse("No request body found", { status: 401 });
}
const job: Job = await req.json();
console.log(`new job parsed: ${job.id}`) // this is not logged
As mentioned, this error only occurs in the vercel function. locally, and deployed elsewhere, the code runs as expected (body is found, function can parse it and move on). As such, I am having difficulty diagnosing why specifically this runtime is having trouble with req.json().
I can note as well that the middleware from the Next project fires before these requests successfully. I wonder if they may be stripping the body somehow? Again though I am finding this hard to diagnose as the setup is identical to node in localhost and hosted online with no trouble.
Thanks in advance for your help.
CURLof how you call the vercel POST api?