我有一个托管在 Heroku 上的应用程序,它发送大量的 JSON。我最初收到 bodyParser - request entity too large 错误(HTTP 400)。谷歌搜索,我遇到了一些 stackoverflow/github 问题链接
(Sails.js bodyParser - 0.10.5 版请求实体太大)(https://github.com/balderdashy/skipper/issues/144)
我尝试更新我的 http.js。现在我的身体解析器看起来像这样:
bodyParser: {
fn: require('skipper'),
options:{
limit: '10mb'
}
}
这解决了 400 错误,但现在我收到 Heroku H13 错误:
2016-08-11T14:02:08.861774+00:00 heroku[router]: at=error code=H13 desc="Connection closed without response"
在这一点上,我有点难过。我查看了 Heroku 关于 H13 错误的文档
(https://devcenter.heroku.com/articles/error-codes#h13-connection-closed-without-response),
但我不确定是否
- 我需要使用 Heroku 进行更多配置(我什至会怎么做)或
- 使用 Sails bodyParser 配置做更多事情或
- 两者的结合
我目前正在使用 Sails 的 0.11.2 版本。
[更新]
研究更多将我带到这些链接:
https://github.com/balderdashy/sails/issues/2653
https://github.com/balderdashy/skipper/issues/22
我注意到一个人在中间件块之外有他们的 bodyParser 配置。我也尝试将我的移动到外面,它似乎解决了我收到的 400 和 503 H13 Heroku 问题(我慢慢地避开了这个问题)。我的新问题是,为什么下面的工作,特别是因为 bodyParser 注释块在中间件块内?
module.exports.http = {
/****************************************************************************
* *
* Express middleware to use for every Sails request. To add custom *
* middleware to the mix, add a function to the middleware config object and *
* add its key to the "order" array. The $custom key is reserved for *
* backwards-compatibility with Sails v0.9.x apps that use the *
* `customMiddleware` config option. *
* *
****************************************************************************/
middleware: {
passportInit: require('passport').initialize(),
passportSession: require('passport').session(),
/***************************************************************************
* *
* 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',
'passportInit',
'passportSession',
'myRequestLogger',
'bodyParser',
'handleBodyParserError',
'compress',
'methodOverride',
'poweredBy',
'$custom',
'router',
'www',
'favicon',
'404',
'500'
],
/****************************************************************************
* *
* Example custom middleware; logs each request to the console. *
* *
****************************************************************************/
// myRequestLogger: function (req, res, next) {
// console.log("Requested :: ", req.method, req.url);
// return next();
// }
/***************************************************************************
* *
* The body parser that will handle incoming multipart HTTP requests. By *
* default as of v0.10, Sails uses *
* [skipper](http://github.com/balderdashy/skipper). See *
* http://www.senchalabs.org/connect/multipart.html for other options. *
* *
***************************************************************************/
// bodyParser: require('skipper')
},
/***************************************************************************
* *
* The number of seconds to cache flat files on disk being served by *
* Express static middleware (by default, these files are in `.tmp/public`) *
* *
* The HTTP static cache is only active in a 'production' environment, *
* since that's the only time Express will cache flat-files. *
* *
***************************************************************************/
// cache: 31557600000
bodyParser: function () {
var opts = {limit:'10mb'};
var fn;
// Default to built-in bodyParser:
fn = require('skipper');
return fn(opts);
}
};