0

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.

zella
  • 4,645
  • 6
  • 35
  • 60
kaytrance
  • 2,657
  • 4
  • 30
  • 49
  • 1
    Are you placing the `bodyParser` config directly under `module.exports.http`, or are you uncommenting the `middleware:` wrapper property in that file as well? Due to an [issue in the Sails config loader](https://github.com/balderdashy/sails/issues/3592), `bodyParser` config must be specified directly under `module.exports.http`. Re: the 502 error, that I can't speak to--is it something you're getting after a timeout? If the request is hanging, you shouldn't be getting a response at all. – sgress454 Feb 22 '16 at 10:25
  • wow!!.. as to I see that you have opened this issue half an hour ago it leads me to conclusion that I was the only one encountered this bug and it was reproduced and issued thanks to you. Looking forwards for developer comments. – kaytrance Feb 22 '16 at 10:54
  • So...that's a yes? Putting the config under `module.exports.http` resolves the issue? I wish I could say this has _never_ been encountered before, but it's been infrequent enough that it has not gotten the attention it deserved. We have a better issue-handling process now, so now that the `bodyParser` problem has popped up again thanks to you, we should be able to address it fairly easily. – sgress454 Feb 22 '16 at 11:39
  • yes, putting `bodyParser` out from `middleware` object and putting right into `module.exports.http` worked for me. I do not know whether I've done it in elegant way or not, but I have declared a `skipper` variable before `module.exports.http` equal to `require('skipper')( { limit: 1024*1024*5 } );` and then in the `bodyParser` I just return `skipper`. – kaytrance Feb 22 '16 at 11:45

1 Answers1

2

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.

Daniel
  • 717
  • 6
  • 21