Replies: 2 comments 6 replies
-
There is a hidden config for this, just export a config object like this:
I found this on: |
Beta Was this translation helpful? Give feedback.
0 replies
-
import type { NextApiRequest, NextApiResponse } from 'next';
import type { Readable } from 'node:stream';
export const config = {
api: {
bodyParser: false,
},
};
async function buffer(readable: Readable) {
const chunks = [];
for await (const chunk of readable) {
chunks.push(typeof chunk === 'string' ? Buffer.from(chunk) : chunk);
}
return Buffer.concat(chunks);
}
export default async function (req: NextApiRequest, res: NextApiResponse) {
if (req.method === 'POST') {
const buf = await buffer(req);
const rawBody = buf.toString('utf8');
res.json({ rawBody });
} else {
res.setHeader('Allow', 'POST');
res.status(405).end('Method Not Allowed');
}
} |
Beta Was this translation helpful? Give feedback.
6 replies
Answer selected by
leerob
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I need to patch incoming graphql requests (due to a missdeployement).
I tried to write a middleware to change the body of the incoming request.
Problem is though, that body parser needs to be disabled, so i have to work with the raw stream.
I can read this stream and convert it to a string and then modify the string, but i don't know how i can modify the request so that my altered string is read.
I tried to override the
req.read
function, but had no success with that. Any other idea?Beta Was this translation helpful? Give feedback.
All reactions