Aconex / drakov

Mock Server that implements the API Blueprint specification
MIT License
481 stars 115 forks source link

Incompatibility with body-parser #170

Closed dgmike closed 6 years ago

dgmike commented 7 years ago

I'm using drakov as middleware on my application as the following.

const app = require('express')();
const bodyParser = require('body-parser');
const drakovMiddleware = require('drakov').middleware;

app.use(bodyParser.json());
app.post('/my-route', (req, res) => {
  res.json({ my: 'response' }).end();
}

argv = {
  sourceFiles: 'docs.md' // have POST to /my-route and another routes
};

drakovMiddleware.init(app, argv, (err, middlewareFunction) => {
    if (err) {
        throw err;
    }
    app.use(middlewareFunction);
    app.listen(argv.serverPort);
});

The idea is to have a mixed application with final and mocked versions. All works fine except when drakov tries to parse the request body. It causes the following error:

TypeError: req.body.trim is not a function
    at getBodyContent (/app/node_modules/drakov/lib/content.js:43:25)
    at Object.exports.matchesBody (/app/node_modules/drakov/lib/content.js:89:19)
    at /app/node_modules/drakov/lib/handler-filter.js:12:24
...

It occurs because body-parser converts the original request.body to JSON object and not a string.

dgmike commented 7 years ago

Any answer for this question?

dgmike commented 6 years ago

bump!

dgmike commented 6 years ago

Closing this issue because there's no iteraction....