我有一個應用程序託管在Heroku上,發送巨大的數量的JSON。我最初得到一個bodyParser - 請求實體太大的錯誤(HTTP 400)。周圍的Googling,遇到幾個計算器來/ GitHub的問題鏈接風帆身體分析器配置
(Sails.js bodyParser - request entity too large on version 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的(我會怎麼連去那配置更多)或
- 與帆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);
}
};
燈泡熄滅 - 合理。謝謝! – danieltjewett