From e8f935d046952dfdf49e21b92c8e20b39b0f50a6 Mon Sep 17 00:00:00 2001 From: Eric Mc Sween Date: Fri, 8 May 2020 11:53:02 -0400 Subject: [PATCH] Make max JSON request size configurable and default to 8 MB This is to allow multi-document updates, for example when creating a new project from a zip file. --- services/document-updater/app.js | 2 +- services/document-updater/config/settings.defaults.js | 2 ++ .../test/acceptance/js/SettingADocumentTests.js | 3 +-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/services/document-updater/app.js b/services/document-updater/app.js index 7555ad666b..e23fa3ca7b 100644 --- a/services/document-updater/app.js +++ b/services/document-updater/app.js @@ -31,7 +31,7 @@ Metrics.event_loop.monitor(logger, 100) const app = express() app.use(Metrics.http.monitor(logger)) -app.use(bodyParser.json({ limit: Settings.max_doc_length + 64 * 1024 })) +app.use(bodyParser.json({ limit: Settings.maxJsonRequestSize })) Metrics.injectMetricsRoute(app) DispatchManager.createAndStartDispatchers(Settings.dispatcherCount || 10) diff --git a/services/document-updater/config/settings.defaults.js b/services/document-updater/config/settings.defaults.js index ff5a35a515..21c3219a33 100755 --- a/services/document-updater/config/settings.defaults.js +++ b/services/document-updater/config/settings.defaults.js @@ -168,6 +168,8 @@ module.exports = { }, max_doc_length: 2 * 1024 * 1024, // 2mb + maxJsonRequestSize: + parseInt(process.env.MAX_JSON_REQUEST_SIZE, 10) || 8 * 1024 * 1024, dispatcherCount: process.env.DISPATCHER_COUNT, diff --git a/services/document-updater/test/acceptance/js/SettingADocumentTests.js b/services/document-updater/test/acceptance/js/SettingADocumentTests.js index 6c13282ba5..2107f46e92 100644 --- a/services/document-updater/test/acceptance/js/SettingADocumentTests.js +++ b/services/document-updater/test/acceptance/js/SettingADocumentTests.js @@ -230,8 +230,7 @@ describe('Setting a document', function () { }) this.newLines = [] while ( - JSON.stringify(this.newLines).length < - Settings.max_doc_length + 64 * 1024 + JSON.stringify(this.newLines).length <= Settings.maxJsonRequestSize ) { this.newLines.push('(a long line of text)'.repeat(10000)) }