I'm using sails version 0.10.5. I have the bodyParser set like so in http.js
:
bodyParser: require('skipper')({
limit: 52428800
})
And I keep getting this error when starting the server:
error: TypeError: Cannot read property 'toLowerCase' of undefined
at _parseHTTPBody (/var/www/testapp-backend/node_modules/skipper/index.js:49:19)
at /var/www/testapp-backend/node_modules/sails/lib/hooks/http/middleware/defaults.js:104:28
at module.exports (/var/www/testapp-backend/node_modules/sails/lib/hooks/http/middleware/defaults.js:144:7)
at loadExpress (/var/www/testapp-backend/node_modules/sails/lib/hooks/http/initialize.js:103:65)
at /var/www/testapp-backend/node_modules/sails/lib/hooks/http/index.js:190:18
at /var/www/testapp-backend/node_modules/sails/lib/app/private/after.js:91:14
at /var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:232:13
at /var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:119:25
at /var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:24:16
at /var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:229:17
at /var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:516:34
at handlerFn (/var/www/testapp-backend/node_modules/sails/lib/app/private/after.js:78:13)
at /var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:511:21
at /var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:227:13
at /var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:111:13
at Array.forEach (native)
at _each (/var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:32:24)
at async.each (/var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:110:9)
at _asyncMap (/var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:226:9)
at Object.map (/var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:204:23)
at _parallel (/var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:509:20)
at Object.async.parallel (/var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:539:9)
at Sails.emitter.after (/var/www/testapp-backend/node_modules/sails/lib/app/private/after.js:89:11)
at Hook.initialize (/var/www/testapp-backend/node_modules/sails/lib/hooks/http/index.js:189:15)
at Hook.bound [as initialize] (/var/www/testapp-backend/node_modules/lodash/dist/lodash.js:729:21)
at /var/www/testapp-backend/node_modules/sails/lib/hooks/index.js:132:16
at /var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:425:17
at /var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:419:17
at Array.forEach (native)
at _each (/var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:32:24)
at Immediate.taskComplete (/var/www/testapp-backend/node_modules/sails/node_modules/async/lib/async.js:418:13)
at processImmediate [as _immediateCallback] (timers.js:367:17) [TypeError: Cannot read property 'toLowerCase' of undefined]
error: Encountered an error when trying to use configured bodyParser.
error: Usually, this means that it was installed incorrectly.
error: A custom bodyParser can be configured without calling the wrapper function- e.g.:
```
bodyParser: require("connect-busboy")
```
error: Alternatively, if you need to provide options:
```
bodyParser: {
fn: require("connect-busboy"),
options: {/* ... */}
}
```
There are no errors there after. What am I doing wrong? I tried following the instructions of the error but with skipper I'm not able to upload files to S3 greater than just a few mb's. I tried this and it doesn't work:
bodyParser: {
fn: require("skipper"),
options: {limit: 52428800}
}
that is as per the message above.
Due to a bug in the default bodyParser
setting in Sails < 0.12, the normal method of configuring the middleware won't work. The easiest solution is to simply replace bodyParser
in the middleware order with another, custom middleware name and configure that instead, e.g.:
module.exports.http = {
middleware: {
// The order in which middleware should be run for HTTP request.
// (the Sails router is invoked by the "router" middleware below.)
order: [
'startRequestTimer',
'cookieParser',
'session',
// 'bodyParser', // <-- don't add the "bodyParser" middleware to the stack
'skipper', // <-- instead use this "custom" middleware
'handleBodyParserError',
'compress',
'methodOverride',
'poweredBy',
'$custom',
'router',
'www',
'favicon',
'404',
'500'
],
// Configure Skipper
skipper: require('skipper')({
limit: 52428800
})
}
}