Skip to content

Commit 72e797b

Browse files
committed
Added config options for setting max upload size
1 parent 553669b commit 72e797b

File tree

5 files changed

+50
-24
lines changed

5 files changed

+50
-24
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# 5.0.0
2+
3+
_Breaking Changes:_
4+
5+
- Removed `xlink:href` from incoming SVGs in preperation for an upcoming puppeteer update that will remove this option.
6+
- Changed the upload file size limit to 3MB, and exposed settings for configuring it (`SERVER_MAX_UPLOAD_SIZE`/`--maxUploadSize`/`maxUploadSize`). The rational behind this change is that in testing that seems like the most balanced limit along with other default values for pool sizing, timeouts and such to avoid attempting to process requests that would likely end up timing out due to its size.
7+
8+
_Fixes:_
9+
10+
- Fixed an issue where clip size for PDFs would on rare occation be invalid, causing the export to fail
11+
- Fixed an issue where the chart constructor was sometimes incorrectly set, causing the export to fail
12+
- Added referrers to CDN cache fetches on first startup/install.
13+
- Fixed an issue that would sometimes cause cause a crash due to fail due to `Accept-Ranges` headers
14+
115
# 4.0.2
216

317
_Hotfix_:

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ The format, along with its default values, is as follows (using the recommended
214214
"host": "0.0.0.0",
215215
"port": 7801,
216216
"benchmarking": false,
217+
"maxUploadSize": 3,
217218
"proxy": {
218219
"host": "",
219220
"port": 8080,
@@ -316,6 +317,7 @@ These variables are set in your environment and take precedence over options fro
316317
- `SERVER_HOST`: The hostname of the server. Additionally, it starts a server listening on the provided hostname (defaults to `0.0.0.0`).
317318
- `SERVER_PORT`: The port to be used for the server when enabled (defaults to `7801`).
318319
- `SERVER_BENCHMARKING`: Indicates whether to display a message with the duration, in milliseconds, of specific actions that occur on the server while serving a request (defaults to `false`).
320+
- `SERVER_MAX_UPLOAD_SIZE`: The maximum size, in MB, of uploaded files (defaults to `3`).
319321

320322
### Server Proxy Config
321323

@@ -413,6 +415,7 @@ _Available options:_
413415
- `--enableServer`: If set to **true**, the server starts on 0.0.0.0 (defaults to `false`).
414416
- `--host`: The hostname of the server. Additionally, it starts a server listening on the provided hostname (defaults to `0.0.0.0`).
415417
- `--port`: The port to be used for the server when enabled (defaults to `7801`).
418+
- `--maxUploadSize`: The maximum size, in MB, of files uploaded through the server (defaults to `3`).
416419
- `--serverBenchmarking`: Indicates whether to display the duration, in milliseconds, of specific actions that occur on the server while serving a request (defaults to `false`).
417420
- `--proxyHost`: The host of the proxy server to use, if it exists (defaults to `false`).
418421
- `--proxyPort`: The port of the proxy server to use, if it exists (defaults to `false`).

lib/schemas/config.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,15 @@ export const defaultConfig = {
348348
}
349349
},
350350
server: {
351+
maxUploadSize: {
352+
value: 3,
353+
type: 'number',
354+
cliName: 'maxUploadSize',
355+
envLink: 'SERVER_MAX_UPLOAD_SIZE',
356+
description:
357+
'The maximum upload size, in megabytes, for the server'
358+
359+
},
351360
enable: {
352361
value: false,
353362
type: 'boolean',

lib/server/server.js

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,6 @@ app.use((_req, res, next) => {
5252
next();
5353
});
5454

55-
// TODO: Read from config/env
56-
// NOTE:
57-
// Too big limits lead to timeouts in the export process when the
58-
// rasterization timeout is set too low.
59-
const uploadLimitMiB = 3;
60-
const uploadLimitBytes = uploadLimitMiB * 1024 * 1024;
61-
62-
// Enable parsing of form data (files) with Multer package
63-
const storage = multer.memoryStorage();
64-
const upload = multer({
65-
storage,
66-
limits: {
67-
fieldSize: uploadLimitBytes
68-
}
69-
});
70-
71-
// Enable body parser
72-
app.use(express.json({ limit: uploadLimitBytes }));
73-
app.use(express.urlencoded({ extended: true, limit: uploadLimitBytes }));
74-
75-
// Use only non-file multipart form fields
76-
app.use(upload.none());
77-
7855
/**
7956
* Attach error handlers to the server.
8057
*
@@ -113,6 +90,29 @@ const attachServerErrorHandlers = (server) => {
11390
*/
11491
export const startServer = async (serverConfig) => {
11592
try {
93+
// TODO: Read from config/env
94+
// NOTE:
95+
// Too big limits lead to timeouts in the export process when the
96+
// rasterization timeout is set too low.
97+
const uploadLimitMiB = serverConfig.maxUploadSize || 3;
98+
const uploadLimitBytes = uploadLimitMiB * 1024 * 1024;
99+
100+
// Enable parsing of form data (files) with Multer package
101+
const storage = multer.memoryStorage();
102+
const upload = multer({
103+
storage,
104+
limits: {
105+
fieldSize: uploadLimitBytes
106+
}
107+
});
108+
109+
// Enable body parser
110+
app.use(express.json({ limit: uploadLimitBytes }));
111+
app.use(express.urlencoded({ extended: true, limit: uploadLimitBytes }));
112+
113+
// Use only non-file multipart form fields
114+
app.use(upload.none());
115+
116116
// Stop if not enabled
117117
if (!serverConfig.enable) {
118118
return false;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"author": "Highsoft AS <[email protected]> (http://www.highcharts.com/about)",
44
"license": "MIT",
55
"type": "module",
6-
"version": "4.0.2",
6+
"version": "5.0.0",
77
"main": "./dist/index.esm.js",
88
"engines": {
99
"node": ">=18.12.0"

0 commit comments

Comments
 (0)