Sails:增加 bodyParser 限制 [英] Sails: increase bodyParser limits
问题描述
在我的应用程序 (sails 0.12.0) 中,我想扩展在 POST 请求时发送的字节数限制.所以在我的 config/http.js
中,我取消了 bodyParser
的注释并将其设置为:
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);
})()
...
}
...
}
但是现在我的每个请求似乎都挂了,结果我在从浏览器发送的每个请求中得到 502 bad gateway
.
But now each my request seems to hang and in result I get 502 bad gateway
in every request sent from browser.
所以:
- 如何正确初始化
skipper
并扩展允许的字节数限制? - 为什么我的所有请求现在都以 502 结尾?
- how do I initialize correctly
skipper
and extend allowed bytes limit? - why all my request now ends up with 502?
EDIT 当@sgress454 询问 bodyParser
的确切位置时,我决定在最初的问题中对其进行精确说明.简而言之,它位于默认配置中注释掉的位置 - middleware
对象下.
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.
推荐答案
错误 as 尚未更新,但现在在 Sails 1.2.3 中对我有用.
The bug as has not been updated, but this now works for me in Sails 1.2.3.
具体来说,使用默认config/http.js
中的示例bodyParser
:
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;
})(),
...
请注意,原始问题在 bodyParser
定义中缺少 ()
.
Note that the original question was missing ()
in the bodyParser
definition.
这篇关于Sails:增加 bodyParser 限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!