diff --git a/CHANGELOG.md b/CHANGELOG.md index 9254b1bb..67a4c0f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 4.1.0 + +_New Features:_ + +- Added `uploadSizeLimit` option (`OTHER_UPLOAD_SIZE_LIMIT` env) [(#580)](https://github.com/highcharts/node-export-server/pull/580). + # 4.0.2 _Hotfix_: diff --git a/README.md b/README.md index effeb48f..8838dc74 100644 --- a/README.md +++ b/README.md @@ -261,7 +261,8 @@ The format, along with its default values, is as follows (using the recommended "listenToProcessExits": true, "noLogo": false, "hardResetPage": false, - "browserShellMode": true + "browserShellMode": true, + "uploadSizeLimit": 52428800 }, "debug": { "enable": false, @@ -371,6 +372,7 @@ These variables are set in your environment and take precedence over options fro - `OTHER_NO_LOGO`: Skip printing the logo on a startup. Will be replaced by a simple text (defaults to `false`). - `OTHER_HARD_RESET_PAGE`: Determines whether the page's content should be reset from scratch, including Highcharts scripts (defaults to `false`). - `OTHER_BROWSER_SHELL_MODE`: Decides whether to enable older but much more performant _shell_ mode for the browser (defaults to `true`). +- `OTHER_UPLOAD_SIZE_LIMIT`: Determines the maximum size of the uploaded file in bytes. The default is 50MB (52428800 bytes). ### Debugging Config - `DEBUG_ENABLE`: Enables or disables debug mode for the underlying browser (defaults to `false`). diff --git a/lib/envs.js b/lib/envs.js index 885d7f07..3f63d14c 100644 --- a/lib/envs.js +++ b/lib/envs.js @@ -207,6 +207,7 @@ export const Config = z.object({ OTHER_NO_LOGO: v.boolean(), OTHER_HARD_RESET_PAGE: v.boolean(), OTHER_BROWSER_SHELL_MODE: v.boolean(), + OTHER_UPLOAD_SIZE_LIMIT: v.positiveNum(), // debugger DEBUG_ENABLE: v.boolean(), diff --git a/lib/schemas/config.js b/lib/schemas/config.js index 50600dfd..aa2d03b7 100644 --- a/lib/schemas/config.js +++ b/lib/schemas/config.js @@ -643,6 +643,13 @@ export const defaultConfig = { type: 'boolean', envLink: 'OTHER_BROWSER_SHELL_MODE', description: 'Decides if the browser runs in the shell mode.' + }, + uploadSizeLimit: { + value: 50 * 1024 * 1024, + type: 'number', + envLink: 'OTHER_UPLOAD_SIZE_LIMIT', + description: + 'The maximum size of the uploaded file in bytes. The default is 50 MB (50 * 1024 * 1024 bytes).' } }, debug: { diff --git a/lib/server/server.js b/lib/server/server.js index 45c03b86..3dbdc540 100644 --- a/lib/server/server.js +++ b/lib/server/server.js @@ -25,6 +25,7 @@ import errorHandler from './error.js'; import rateLimit from './rate_limit.js'; import { log, logWithStack } from '../logger.js'; import { __dirname } from '../utils.js'; +import { getOptions } from '../config.js'; import vSwitchRoute from './routes/change_hc_version.js'; import exportRoutes from './routes/export.js'; @@ -45,22 +46,6 @@ app.disable('x-powered-by'); // Enable CORS support app.use(cors()); -// Enable parsing of form data (files) with Multer package -const storage = multer.memoryStorage(); -const upload = multer({ - storage, - limits: { - fieldSize: 50 * 1024 * 1024 - } -}); - -// Enable body parser -app.use(express.json({ limit: 50 * 1024 * 1024 })); -app.use(express.urlencoded({ extended: true, limit: 50 * 1024 * 1024 })); - -// Use only non-file multipart form fields -app.use(upload.none()); - /** * Attach error handlers to the server. * @@ -93,6 +78,25 @@ const attachServerErrorHandlers = (server) => { * and started. */ export const startServer = async (serverConfig) => { + const uploadSizeLimit = + getOptions()?.other?.uploadSizeLimit || 50 * 1024 * 1024; + + // Enable parsing of form data (files) with Multer package + const storage = multer.memoryStorage(); + const upload = multer({ + storage, + limits: { + fieldSize: uploadSizeLimit + } + }); + + // Enable body parser + app.use(express.json({ limit: uploadSizeLimit })); + app.use(express.urlencoded({ extended: true, limit: uploadSizeLimit })); + + // Use only non-file multipart form fields + app.use(upload.none()); + try { // Stop if not enabled if (!serverConfig.enable) {