Added body parser to web/api/v2 express app

refs #9866

- req.body is undefined if we don't use the body parser
- the content API only offers "fetch" endpoints, but if a component/module in Ghost relies on req.body being present, it can crash
- e.g. the authentication service checks for the existence of client_id + client_secret in req.query or req.body
- we could theoretically change it from `if (!req.body.client_id` to `if (req.body && !req.body.client_id)`, but that makes the code very hard to read + maintain
- we will use the body parser for the content API now
- req.body will be {}
This commit is contained in:
kirrg001 2018-10-03 00:47:03 +02:00
parent 27996db5e9
commit 079b41e608

View File

@ -1,5 +1,6 @@
const debug = require('ghost-ignition').debug('api');
const boolParser = require('express-query-boolean');
const bodyParser = require('body-parser');
const express = require('express');
const shared = require('../../../shared');
const routes = require('./routes');
@ -10,6 +11,9 @@ module.exports = function setupApiApp() {
// API middleware
// @NOTE: req.body is undefined if we don't use this parser, this can trouble if components rely on req.body being present
apiApp.use(bodyParser.json({limit: '1mb'}));
// Query parsing
apiApp.use(boolParser());