From 65656a9cf416df561e72b7d288024926588f4f02 Mon Sep 17 00:00:00 2001 From: Rish Date: Fri, 22 May 2020 14:25:13 +0530 Subject: [PATCH] Removed global bodyParser middleware for members app no issue - Removes global bodyParser middleware for membersApp and adds it to specific endpoints - Removes global boolParser middleware for membersApp We added bodayParser middleware to memebrsApp in [this](https://github.com/TryGhost/Ghost/commit/fe3eab18364f13114b6cd02af82f8b2c4d9ba14b) commit to read json requests for members update endpoint, but that had issues with stripe webhook parsing for `/webhooks` endpoint as stripe expects raw data to be passed down. --- core/server/web/members/app.js | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/core/server/web/members/app.js b/core/server/web/members/app.js index 16c6eede2e..c1307d5461 100644 --- a/core/server/web/members/app.js +++ b/core/server/web/members/app.js @@ -2,7 +2,6 @@ const debug = require('ghost-ignition').debug('web:members:app'); const {URL} = require('url'); const cors = require('cors'); const bodyParser = require('body-parser'); -const boolParser = require('express-query-boolean'); const express = require('../../../shared/express'); const urlUtils = require('../../lib/url-utils'); const membersService = require('../../services/members'); @@ -13,13 +12,6 @@ module.exports = function setupMembersApp() { debug('Members App setup start'); const membersApp = express('members'); - // Body parsing - membersApp.use(bodyParser.json({limit: '1mb'})); - membersApp.use(bodyParser.urlencoded({extended: true, limit: '1mb'})); - - // Query parsing - membersApp.use(boolParser()); - // send 503 json response in case of maintenance membersApp.use(shared.middlewares.maintenance); @@ -39,8 +31,9 @@ module.exports = function setupMembersApp() { membersApp.post('/webhooks/stripe', middleware.stripeWebhooks); // Initializes members specific routes as well as assigns members specific data to the req/res objects + // We don't want to add global bodyParser middleware as that interfers with stripe webhook requests on - `/webhooks`. membersApp.get('/api/member', middleware.getMemberData); - membersApp.put('/api/member', middleware.updateMemberData); + membersApp.put('/api/member', bodyParser.json({limit: '1mb'}), middleware.updateMemberData); membersApp.get('/api/session', middleware.getIdentityToken); membersApp.delete('/api/session', middleware.deleteSession); membersApp.get('/api/site', middleware.getMemberSiteData);