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.
I'm using drakov as middleware on my application as the following.
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:
It occurs because
body-parser
converts the originalrequest.body
to JSON object and not a string.