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

add max request size option #536

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 11 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var EventEmitter = require('events').EventEmitter;
* @param {Number} options.cacheLongSeconds - The time to cache long lived cache responses.
* @param {String} options.routePrefix - The URL route prefix
* @param {String} options.translateAddresses - Translate request and output address to Copay's BCH address version (see https://support.bitpay.com/hc/en-us/articles/115004671663-BitPay-s-Adopted-Conventions-for-Bitcoin-Cash-Addresses-URIs-and-Payment-Requests)
* @param {String} options.maxRequestSize - Max size of request body for body parser to handle e.g '20mb'
*/
var InsightAPI = function(options) {
BaseService.call(this, options);
Expand Down Expand Up @@ -59,6 +60,8 @@ var InsightAPI = function(options) {
this.blockSummaryCacheSize = options.blockSummaryCacheSize || BlockController.DEFAULT_BLOCKSUMMARY_CACHE_SIZE;
this.blockCacheSize = options.blockCacheSize || BlockController.DEFAULT_BLOCK_CACHE_SIZE;

this.maxRequestSize = options.maxRequestSize;

if (!_.isUndefined(options.routePrefix)) {
this.routePrefix = options.routePrefix;
} else {
Expand Down Expand Up @@ -174,8 +177,14 @@ InsightAPI.prototype.setupRoutes = function(app) {
//Enable compression
app.use(compression());

//Enable urlencoded data
app.use(bodyParser.urlencoded({extended: true}));
//Set max request size default:100kb
if(this.maxRequestSize){
app.use(bodyParser.urlencoded({limit: this.maxRequestSize, extended: true}))
}else {
//Enable urlencoded data
app.use(bodyParser.urlencoded({extended: true}));
}


//Enable CORS
app.use(function(req, res, next) {
Expand Down