diff --git a/src/middleware/json.js b/src/middleware/json.js index 0f73ddd98..a3c45d3f6 100644 --- a/src/middleware/json.js +++ b/src/middleware/json.js @@ -7,12 +7,12 @@ function _mime(req) { return str.split(';')[0]; } -exports = module.exports = function (options) { +exports = module.exports = function (options, forceContentType = true) { const json = express.json(options); return function (req, res, next) { // enforce json body type. without this the json middleware will skip parsing and req.body might be undefined - if (_mime(req) !== 'application/json') return res.status(400).send('incorrect mime type. expecting application/json'); + if (forceContentType && _mime(req) !== 'application/json') return res.status(400).send('incorrect mime type. expecting application/json'); json(req, res, next); }; };