I'm trying to integrate a local payment gateway (not stripe), that demands the raw body for validating the webhook.
I first tried using await req.text(), as this seems to be the natural solution to this.
export async function POST(req: Request) {
const data = await req.json();
try {
const rawBody = await req.text();
console.log("rawbody: " + rawBody);
} catch (err) {
console.log("req.text error");
console.log(err?.message!);
}
}
But that gives me this error:
req.text error
Body is unusable
I also tried to tweak the config for this endpoint so that the parsing is disabled, by doing this.
export const config = {
api: {
bodyParser: false,
},
};
It seems like this is deprecated now, I get the below warning. And the link does not have any parsing-related config options.
⚠ Page config in C:{project}\app\api\cf-webhook-offload\route.ts is deprecated. Replace export const config=… with the following:
Visit https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config for more information.
The req.json() parses to an object that I expect from the webhook properly.
Is there any way I turn this into rawBody?
This is supposed to be straightforward, and I feel like I'm missing something trivial here.
Thanks.