I am trying to access Post request body in my UI nuxt app
So someone hit my url with the POST call with body, I can get that request body.
I created middleware which gives console log when I try post call with postman.
Nuxt.config
ServerMiddleware:[{path:'test1',handler:'~middleware/loggertest'}]
And my middleware
export default function(req, res, next) {
if (req.method === ‘POST’) {
let body = ‘’;
req.on(‘data’, chunk => {
body += chunk.toString();
})
req.on(‘end’, () => {
console.log(‘Request body:’, body);
next();
})
} else {
next();
}
}
But when try to add commit or context or app inside to store that value and access in my vue app my middleware stop console or my app stops loading.
How I can store the variable which I can access in my vue component
I am using nuxt 2.12.2