feat: use config file for maxRequestBodySize

closes !20
This commit is contained in:
Wieland Schöbl
2019-02-27 14:43:05 +01:00
committed by Rainer Killinger
parent eabd885cd4
commit d110d60123

View File

@@ -14,6 +14,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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