Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/upload-size-configurable #580

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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_:
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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`).
Expand Down
1 change: 1 addition & 0 deletions lib/envs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
7 changes: 7 additions & 0 deletions lib/schemas/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
36 changes: 20 additions & 16 deletions lib/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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.
*
Expand Down Expand Up @@ -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) {
Expand Down
Loading