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: allow to specify request body size limit #345

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion docs/ServerConfiguration.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ Here is an example config with all the currently supported options. See descript
key: 'path/to/key.pem',
cert: 'path/to.cert.pem'
},
publicDirectory: '/path/to/public'
publicDirectory: '/path/to/public',
requestSizeLimit: '10mb'
},
logging: {
level: 'debug'
Expand Down Expand Up @@ -194,6 +195,13 @@ const fhirConfig = {
- **Required:** No.
- **Default:** `none`

#### `server.requestSizeLimit`

- **Type:** `string`
- **Description:** Controls the maximum request body size. The value is passed to [body-parser](https://www.npmjs.com/package/body-parser) library. If no value is provided, the library uses default `'100kb'`.
- **Required:** No.
- **Default:** `none`

#### `logging.level`

> Currently this is the only logging configuration supported. We use Winston for logging and will eventually add support for more options.
Expand Down
14 changes: 12 additions & 2 deletions packages/node-fhir-server-core/src/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,18 @@ class Server {
// Add compression
this.app.use(compression({ level: 9 }));
// Enable the body parser
this.app.use(bodyParser.urlencoded({ extended: true }));
this.app.use(bodyParser.json({ type: ['application/fhir+json', 'application/json+fhir'] }));
this.app.use(
bodyParser.urlencoded({
extended: true,
limit: this.config.server.requestSizeLimit,
}),
);
this.app.use(
bodyParser.json({
type: ['application/fhir+json', 'application/json+fhir'],
limit: this.config.server.requestSizeLimit,
}),
);
// Enable @hapi/bourne to protect against prototype injection
this.app.use(prototypeInjectionHandler);
// Set favicon
Expand Down