web: configure payload size
This commit is contained in:
parent
5e5551afbf
commit
b7f888fc3e
|
@ -37,6 +37,10 @@ var WebService = function(options) {
|
|||
this.httpsOptions = options.httpsOptions || this.node.httpsOptions;
|
||||
this.port = options.port || this.node.port || 3456;
|
||||
|
||||
// set the maximum size of json payload, defaults to express default
|
||||
// see: https://github.com/expressjs/body-parser#limit
|
||||
this.jsonRequestLimit = options.jsonRequestLimit || '100kb';
|
||||
|
||||
this.enableSocketRPC = _.isUndefined(options.enableSocketRPC) ?
|
||||
WebService.DEFAULT_SOCKET_RPC : options.enableSocketRPC;
|
||||
|
||||
|
@ -59,7 +63,7 @@ WebService.DEFAULT_SOCKET_RPC = true;
|
|||
*/
|
||||
WebService.prototype.start = function(callback) {
|
||||
this.app = express();
|
||||
this.app.use(bodyParser.json());
|
||||
this.app.use(bodyParser.json({limit: this.jsonRequestLimit}));
|
||||
|
||||
if(this.https) {
|
||||
this.transformHttpsOptions();
|
||||
|
|
|
@ -46,6 +46,10 @@ describe('WebService', function() {
|
|||
var web3 = new WebService({node: defaultNode});
|
||||
web3.enableSocketRPC.should.equal(WebService.DEFAULT_SOCKET_RPC);
|
||||
});
|
||||
it('will set configuration options for max payload', function() {
|
||||
var web = new WebService({node: defaultNode, jsonRequestLimit: '200kb'});
|
||||
web.jsonRequestLimit.should.equal('200kb');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#start', function() {
|
||||
|
@ -75,6 +79,39 @@ describe('WebService', function() {
|
|||
done();
|
||||
});
|
||||
});
|
||||
it('should pass json request limit to json body parser', function(done) {
|
||||
var node = new EventEmitter();
|
||||
var jsonStub = sinon.stub();
|
||||
var TestWebService = proxyquire('../../lib/services/web', {
|
||||
http: {
|
||||
createServer: sinon.stub()
|
||||
},
|
||||
https: {
|
||||
createServer: sinon.stub()
|
||||
},
|
||||
fs: fsStub,
|
||||
express: sinon.stub().returns({
|
||||
use: sinon.stub()
|
||||
}),
|
||||
'body-parser': {
|
||||
json: jsonStub
|
||||
},
|
||||
'socket.io': {
|
||||
listen: sinon.stub().returns({
|
||||
on: sinon.stub()
|
||||
})
|
||||
}
|
||||
});
|
||||
var web = new TestWebService({node: node});
|
||||
web.start(function(err) {
|
||||
if (err) {
|
||||
return done(err);
|
||||
}
|
||||
jsonStub.callCount.should.equal(1);
|
||||
jsonStub.args[0][0].limit.should.equal('100kb');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#stop', function() {
|
||||
|
|
Loading…
Reference in New Issue