我正在尝试更改Sails JS应用程序的设置,并有点麻烦将参数传递给body解析器,以便更改默认设置。
我之前在这里描述过这个问题:
Posting larger files
我相信通过更改默认的“limit”选项已经正确地解决了这个问题,因为100kb的默认大小减去formData对象33%的开销与我可以/不能发送的文件大小非常一致。所以建议的解决方案是:
var bodyParser = require('body-parser');
...
app.use(bodyParser.urlencoded( { limit: 1048576 } ));
但我无法在我的Sails应用程序中实现该解决方案。我已经看完了
Sails Documentation
在更改中间件设置时,在我的config/http.js文件中尝试了以下操作。。。
首次尝试-包装
/**
* HTTP Server Settings
* (sails.config.http)
*/
module.exports.http = {
middleware: {
order: [
'startRequestTimer',
'cookieParser',
'session',
'refreshSessionCookie',
'bodyParserInit',
'bodyParser',
'handleBodyParserError',
'compress',
'methodOverride',
'poweredBy',
'$custom',
'requestLogger',
'router',
'www',
'favicon',
'404',
'500'
],
bodyParserInit : (function (){
let bodyParser = require('body-parser');
return bodyParser( { extended: true, limit: 1073741824 } )
})(),
)
},
// cache: 31557600000
};
第二次尝试-覆盖
/**
* HTTP Server Settings
* (sails.config.http)
*/
module.exports.http = {
middleware: {
order: [
'startRequestTimer',
'cookieParser',
'session',
'refreshSessionCookie',
//'bodyParserInit',
'bodyParser',
'handleBodyParserError',
'compress',
'methodOverride',
'poweredBy',
'$custom',
'requestLogger',
'router',
'www',
'favicon',
'404',
'500'
],
bodyParser: (function _configureBodyParser(){
let skipper = require('skipper');
let middlewareFn = skipper({
limit: 1073741824,
});
return middlewareFn;
})(),
)
},
// cache: 31557600000
};
然而,这两次尝试都没有解决我的问题,因为无论我做了什么,限制似乎仍然设置为100kb。如何正确实现此功能,以便主体解析器接受高达50kb的文件?我想可能是我没有正确配置,或者是别的什么东西覆盖了我所做的。
编辑
:我使用的是Sails版本>12.0.X