Skip to content
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
5 changes: 5 additions & 0 deletions .changeset/nasty-donkeys-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@koopjs/koop-core': minor
---

Allow bodyParser.urlencoded.limit to be set by options.urlencodedLimit
22 changes: 22 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ 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).

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

```js
const options = {
urlencodedLimit: '500kb'
}
```

> 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
2 changes: 1 addition & 1 deletion packages/core/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ function initServer(options) {
// parse application/json
.use(bodyParser.json({ limit: options.bodyParserLimit || '10000kb' }))
// parse application/x-www-form-urlencoded
.use(bodyParser.urlencoded({ extended: false }))
.use(bodyParser.urlencoded({ limit: options.urlencodedLimit || '100kb', extended: false }))
.disable('x-powered-by')
// for demos and preview maps in providers
.set('view engine', 'ejs')
Expand Down
24 changes: 24 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,23 @@ 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);
const args = mockBodyParser.json.getCall(0).args[0];
args.should.have.property('limit', '20mb');
});

it('should modify urlencodedLimit', function () {
new Koop({ urlencodedLimit: '10mb' });

mockApp.use.callCount.should.equal(5);
const args = mockBodyParser.urlencoded.getCall(0).args[0];
args.should.have.property('extended', false);
args.should.have.property('limit', '10mb');
});
});

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