Skip to content

Commit

Permalink
docs: document bodyParserLimit option (#624)
Browse files Browse the repository at this point in the history
Added documentation for koop option `bodyParserLimit` (for POST maximum body size). Also added some
unit tests.
  • Loading branch information
ns-mwoo committed Dec 21, 2024
1 parent 5f6379a commit 01acabd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
11 changes: 11 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ const options = {
}
```

#### bodyParserLimit (or maximum POST body size)
Koop configures Express maximum body size to 10mb by default. If you want to decrease or increase that size, you can do so by adding a `bodyParserLimit` value to your Koop config file:

```js
const options = {
bodyParserLimit: '20mb'
}
```

> See [Supported units and abbreviations](https://www.npmjs.com/package/bytes#bytesparsestringnumber-value-numbernull).
#### logger
Koop includes a Winston logger with a console transport by default. If you have a custom logger that you want to use, you can pass it as an option:

Expand Down
14 changes: 14 additions & 0 deletions packages/core/src/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ const DataProvider = require('./data-provider');

const providerConstructorSpy = sinon.spy();

const mockBodyParser = {
json: sinon.spy(() => {}),
urlencoded: sinon.spy(() => {}),
};

const mockApp = {
use: sinon.spy(() => mockApp),
disable: sinon.spy(() => mockApp),
Expand Down Expand Up @@ -44,6 +49,7 @@ const Koop = proxyquire('./', {
'./data-provider': mockDataProviderModule,
'@koopjs/logger': MockLogger,
express: mockExpress,
'body-parser': mockBodyParser,
});

class MockProviderPluginController {
Expand Down Expand Up @@ -91,6 +97,7 @@ describe('Index tests', function () {
const koop = new Koop();
koop.config.should.be.empty();
mockApp.use.callCount.should.equal(5);
mockBodyParser.json.calledWith({ limit: '10000kb' });
});

it('should instantiate Koop with options', function () {
Expand All @@ -109,6 +116,13 @@ describe('Index tests', function () {

mockApp.use.callCount.should.equal(3);
});

it('should modify bodyParserLimit', function () {
new Koop({ bodyParserLimit: '20mb' });

mockApp.use.callCount.should.equal(5);
mockBodyParser.json.calledWith({ limit: '20mb' });
});
});

describe('Plugin registration', function () {
Expand Down

0 comments on commit 01acabd

Please sign in to comment.