uptownhr / nuxt-express-module

Add express routes to your nuxt app
MIT License
61 stars 4 forks source link

How to use body-parser for post-resources #10

Open bergjos opened 4 years ago

bergjos commented 4 years ago

I created a post-resource trying to accept some data via the post-body:

router.post('/api/testPost', (req, res) => { console.log(req.params); //It works! console.log(req.query); //It works! console.log(req.body); // Doesn't work due to missing body-parsing });

After a quick research, I realized, that there isn't any body-parsing in the nuxt-express-module. If you create a express-server without nuxt, you would use something like that: const bodyParser = require('body-parser') // parse application/x-www-form-urlencoded app.use(bodyParser.urlencoded({ extended: false })) // parse application/json app.use(bodyParser.json())

In my opinion it would be nice, to create a possibillity via the options, to use a body-parser.

uptownhr commented 4 years ago

thanks for creating an issue. I need to double-check but this module may not be needed anymore. I believe nuxt today may have this baked in.

uptownhr commented 4 years ago

Found it. https://nuxtjs.org/api/configuration-servermiddleware/#usage