Sails: increase bodyParser limits

可紊 提交于 2019-12-10 12:23:42

问题


In my app (sails 0.12.0) I want to extend a limit of bytes send upon POST request. So in my config/http.js I am uncommenting bodyParser and set it to:

module.exports.http = {

    ...

    middleware: {
        ...

        bodyParser: (function () {
            var opts = {limit: 1024*1024*5}; // set it to 5 megabytes
            var fn;

            // Default to built-in bodyParser:
            fn = require('skipper');
            return fn(opts);

        })()

        ...
    }

    ...
}

But now each my request seems to hang and in result I get 502 bad gateway in every request sent from browser.

So:

  • how do I initialize correctly skipper and extend allowed bytes limit?
  • why all my request now ends up with 502?

EDIT as @sgress454 inquired about where exactly bodyParser is located I'have decided to precise it in initial question. In short it was located just where it is commented out in default config - under middleware object.

It turns out it's a bug and the issue has been created, so please follow it for further development.


回答1:


The bug as has not been updated, but this now works for me in Sails 1.2.3.

Specifically, using the example bodyParser in the default config/http.js:

...
bodyParser: (function _configureBodyParser(){
  var skipper = require('skipper');
  var middlewareFn = skipper({
    // strict: true,
    limit: '10mb',
  });
  return middlewareFn;
})(),
...

Note that the original question was missing () in the bodyParser definition.



来源:https://stackoverflow.com/questions/35548287/sails-increase-bodyparser-limits

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!