Make max payload size configurable #1447

This commit is contained in:
Jan Oberhauser 2021-04-09 12:13:42 +02:00
parent 3c48b06884
commit 2273a4cff2
2 changed files with 11 additions and 3 deletions

View file

@ -446,6 +446,12 @@ const config = convict({
}, },
endpoints: { endpoints: {
payloadSizeMax: {
format: Number,
default: 16,
env: 'N8N_PAYLOAD_SIZE_MAX',
doc: 'Maximum payload size in MB.',
},
metrics: { metrics: {
enable: { enable: {
format: 'Boolean', format: 'Boolean',

View file

@ -132,6 +132,7 @@ class App {
protocol: string; protocol: string;
sslKey: string; sslKey: string;
sslCert: string; sslCert: string;
payloadSizeMax: number;
presetCredentialsLoaded: boolean; presetCredentialsLoaded: boolean;
@ -145,6 +146,7 @@ class App {
this.saveManualExecutions = config.get('executions.saveDataManualExecutions') as boolean; this.saveManualExecutions = config.get('executions.saveDataManualExecutions') as boolean;
this.executionTimeout = config.get('executions.timeout') as number; this.executionTimeout = config.get('executions.timeout') as number;
this.maxExecutionTimeout = config.get('executions.maxTimeout') as number; this.maxExecutionTimeout = config.get('executions.maxTimeout') as number;
this.payloadSizeMax = config.get('endpoints.payloadSizeMax') as number;
this.timezone = config.get('generic.timezone') as string; this.timezone = config.get('generic.timezone') as string;
this.restEndpoint = config.get('endpoints.rest') as string; this.restEndpoint = config.get('endpoints.rest') as string;
@ -369,7 +371,7 @@ class App {
// Support application/json type post data // Support application/json type post data
this.app.use(bodyParser.json({ this.app.use(bodyParser.json({
limit: '16mb', verify: (req, res, buf) => { limit: this.payloadSizeMax + 'mb', verify: (req, res, buf) => {
// @ts-ignore // @ts-ignore
req.rawBody = buf; req.rawBody = buf;
}, },
@ -378,7 +380,7 @@ class App {
// Support application/xml type post data // Support application/xml type post data
// @ts-ignore // @ts-ignore
this.app.use(bodyParser.xml({ this.app.use(bodyParser.xml({
limit: '16mb', xmlParseOptions: { limit: this.payloadSizeMax + 'mb', xmlParseOptions: {
normalize: true, // Trim whitespace inside text nodes normalize: true, // Trim whitespace inside text nodes
normalizeTags: true, // Transform tags to lowercase normalizeTags: true, // Transform tags to lowercase
explicitArray: false, // Only put properties in array if length > 1 explicitArray: false, // Only put properties in array if length > 1
@ -386,7 +388,7 @@ class App {
})); }));
this.app.use(bodyParser.text({ this.app.use(bodyParser.text({
limit: '16mb', verify: (req, res, buf) => { limit: this.payloadSizeMax + 'mb', verify: (req, res, buf) => {
// @ts-ignore // @ts-ignore
req.rawBody = buf; req.rawBody = buf;
}, },