How can I use body-parser with LoopBack?

前端 未结 8 708
别那么骄傲
别那么骄傲 2020-12-24 13:56

I see that LoopBack has the Express 3.x middleware built-in. Indeed, body-parser is in loopback/node_modules. But I cannot figure out how to use it as middlewar

8条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-24 14:48

    In Loopback ^3.22.0, I can suffice by adding the

    "parse": {
        "body-parser#json": {}
      },
    

    to the server/middleware.json in order to consume application/json post bodies in the server/boot/routes.js

    module.exports = function(app) {
      app.post('/api/sayhello', function(req, res, next) {
         console.log(req.body)
    

提交回复
热议问题