From ee133fd280413acaac201ff7b63fe567d86e7d1b Mon Sep 17 00:00:00 2001 From: Eric Date: Tue, 16 May 2023 12:09:02 -0500 Subject: [PATCH] Website: Update Fleet website's body parser limit (#11701) Closes: #11686 Changes: - Updated `website/config/http.js` to increase the `limit` of the Fleet website's body-parser to 1mb (from the default 100kb) to support Fleet instances sending usage analytics with large amounts of JSON. --- website/config/http.js | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/website/config/http.js b/website/config/http.js index 3cf438f1ff..16ba0a25b1 100644 --- a/website/config/http.js +++ b/website/config/http.js @@ -49,11 +49,23 @@ module.exports.http = { * * ***************************************************************************/ - // bodyParser: (function _configureBodyParser(){ - // var skipper = require('skipper'); - // var middlewareFn = skipper({ strict: true }); - // return middlewareFn; - // })(), + bodyParser: (function _configureBodyParser(){ + var skipper = require('skipper'); + var middlewareFn = skipper({ + strict: true, + limit: '1MB',// [?] https://github.com/expressjs/body-parser/tree/ee91374eae1555af679550b1d2fb5697d9924109#limit-1 + onBodyParserError: (err, req, res)=>{ + // If an error occurs while parsing an incoming request body, we'll return a badRequest response if error.statusCode is between 400-500 + if (_.isNumber(err.statusCode) && err.statusCode >= 400 && err.statusCode < 500) { + return res.status(400).send(err.message); + } else { + sails.log.error('Sending 500 ("Server Error") response: \n', err); + return res.status(500).send(); + } + } + }); + return middlewareFn; + })(), },