From d110d60123a28563fe0c58ab903f61255a9644a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wieland=20Sch=C3=B6bl?= Date: Wed, 27 Feb 2019 14:43:05 +0100 Subject: [PATCH] feat: use config file for maxRequestBodySize closes !20 --- src/app.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/app.ts b/src/app.ts index 58598bdc..ef93ea80 100644 --- a/src/app.ts +++ b/src/app.ts @@ -14,6 +14,7 @@ * along with this program. If not, see . */ import { + SCConfigFile, SCNotFoundErrorResponse, SCRequestBodyTooLargeErrorResponse, SCSyntaxErrorResponse, @@ -40,6 +41,7 @@ import {Elasticsearch} from './storage/elasticsearch/Elasticsearch'; export const app = express(); const isTestEnvironment = process.env.NODE_ENV !== 'production'; +const configFile: SCConfigFile = app.get('config'); async function configureApp() { // request loggers have to be the first middleware to be set in express @@ -73,7 +75,7 @@ async function configureApp() { const chunkGatherer = (chunk: Buffer) => { bodySize += chunk.byteLength; // when adding each chunk size to the total size, check how large it now is. - if (bodySize > 512 * 1024) { + if (bodySize > configFile.backend.maxRequestBodySize) { req.off('data', chunkGatherer); req.off('end', endCallback); // return an error in the response