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

Cannot load custom bodyParser config from sails.config.http.middleware.bodyParser #3592

Closed
sgress454 opened this issue Feb 22, 2016 · 2 comments
Labels

Comments

@sgress454
Copy link
Member

To reproduce:

  1. In config/http.js, uncomment example middleware config (at minimum the middleware: { property and closing }, and the bodyParser: require('skipper') line.
  2. sails lift
  3. Make any request (e.g. to the homepage) and notice that the request hangs.

The issue is that in defaults.js in the HTTP hook code we go to great lengths to allow overriding of the body parser via sails.config.http.middleware.bodyParser, but since all of that code is wrapped in _.defaults(), the result of the self-calling function is never actually used, because a value already exists for the bodyParser key. In the example above, the loaded body parser would be the result of require('skipper'), which is not itself valid (it needs to be called w/ options). Furthermore, doing:

bodyParser: require('skipper')(<some options>)

doesn't work, because the self-calling function in defaults.js would then call that resulting function, resulting in an error.

Currently the only way to customize the bodyParser is via sails.config.http.bodyParser (not middleware.bodyParser). We should probably keep this for backwards-compatibility (with a deprecation warning), but in the self-calling function in defaults.js, just return early if sails.config.http.middleware.bodyParser is defined.

@sgress454 sgress454 added the bug label Feb 22, 2016
@sgress454
Copy link
Member Author

Note to self, reply in http://stackoverflow.com/questions/35548287/sails-increase-bodyparser-limits when this is fixed.

@danielsharvey
Copy link
Contributor

Note to self, reply in http://stackoverflow.com/questions/35548287/sails-increase-bodyparser-limits when this is fixed.

This now works for me (sails 1.2.3) using the example bodyParser in config/http.js.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants