From 542dff70bf8fa7aaea975956a72424e0b6155e87 Mon Sep 17 00:00:00 2001 From: Oskar Hladky Date: Fri, 15 Dec 2017 10:39:31 +0100 Subject: [PATCH] add max request size option --- lib/index.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/index.js b/lib/index.js index c6519cf9f..197f3538d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -27,7 +27,8 @@ var EventEmitter = require('events').EventEmitter; * @param {Number} options.cacheShortSeconds - The time to cache short lived cache responses. * @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.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); @@ -53,6 +54,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 { @@ -164,8 +167,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) {