Currently using the next Next.JS 13 Route Handler to process information passed by a form. And I m trying to figure out why I can t get the new Route Handler to function despite mirroring the doc (above link) code.
export async function POST( request: Request) {
console.log( Body , request.body)
const res = await request.json();
...
}
But when trying to process the request data, I get an error:
Body ReadableStream { locked: false, state: readable , supportsBYOB: false }
error - SyntaxError: Unexpected token d , "dqaf=ll" is not valid JSON
at JSON.parse (<anonymous>)
at parseJSONFromBytes (node:internal/deps/undici/undici:6444:19)
at successSteps (node:internal/deps/undici/undici:6418:27)
at node:internal/deps/undici/undici:1133:60
at node:internal/process/task_queues:140:7
at AsyncResource.runInAsyncScope (node:async_hooks:204:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Request raw body sent by postman:
dqaf=ll
页: 1
我将手稿改成一个皮路,载于/pages/api/contactForm.j
。 (并拆除了预防冲突的路手)看来行之有效:
export default function handler(req, res) {
const body = req.body
console.log( body: , body)
}
Logs:
body: dqaf=ll
我在路边做一些不正确的事情吗?
I ve tried turning off the bodyParser by including the following code in
export const config = {
api: {
bodyParser: false,
}
}
Logs:
error - SyntaxError: Unexpected token d , "dqaf=ll" is not valid JSON
at JSON.parse (<anonymous>)
at parseJSONFromBytes (node:internal/deps/undici/undici:6444:19)
at successSteps (node:internal/deps/undici/undici:6418:27)
at node:internal/deps/undici/undici:1133:60
at node:internal/process/task_queues:140:7
at AsyncResource.runInAsyncScope (node:async_hooks:204:9)
at AsyncResource.runMicrotask (node:internal/process/task_queues:137:8)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
我最后将采用<代码>/pages/api目前处理路线的格式,但如果我从路上找不到东西,或者如果这是用新的第13条 next子的ug子,我会想理解吗?