简体   繁体   中英

Setting Request Limit in a Meteor.js App

I am trying to send a very large amount of JSON to a server side route in my Meteor.js Application. I keep on getting this error...

Error: Request Entity Too Large at Object.exports.error (/mnt/data/2/node_modules/connect/lib/utils.js:62:13) at limit (/mnt/data/2/node_modules/connect/lib/middleware/limit.js:46:47) at urlencoded (/mnt/data/2/node_modules/connect/lib/middleware/urlencoded.js:58:5) at /mnt/data/2/node_modules/connect/lib/middleware/bodyParser.js:55:7 at json (/mnt/data/2/node_modules/connect/lib/middleware/json.js:46:55) at Object.bodyParser [as handle] (/mnt/data/2/node_modules/connect/lib/middleware/bodyParser.js:53:5) at next (/mnt/data/2/node_modules/connect/lib/proto.js:190:15) at Object.query [as handle] (/mnt/data/2/node_modules/connect/lib/middleware/query.js:44:5) at next (/mnt/data/2/node_modules/connect/lib/proto.js:190:15) at Object.Package [as handle] (packages/spiderable/spiderable.js:108)

In my research I have found that I need to set the request limit for the connect middleware. Does anyone know how I can do this within Meteor? Thanks!

Another solution is to add the following code somewhere on the server (eg, Meteor.startup ):

Router.configureBodyParsers = function() {
  Router.onBeforeAction(Iron.Router.bodyParser.urlencoded({
    extended: true,
    limit: '100mb'
  }));
};

( ref )

So after a while of trial and error what ended up working for me was modifying the IronRouter package. /lib/server/router.js on line 30 change...

start: function () {
connectHandlers
  .use(connect.query())
  .use(connect.bodyParser())
  .use(_.bind(this.onRequest, this)); },

to...

start: function () {
connectHandlers
  .use(connect.query())
  .use(connect.bodyParser({limit: '100mb'})) // or whatever you want your limit to be
  .use(_.bind(this.onRequest, this)); },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM