Express / NodeJS:stderr:错误:请求实体太大

时间:2015-11-09 14:36:14

标签: node.js express

有以下代码:

var url             = require('url');
var proxy           = require('express-http-proxy');
var localConfig     = require('./config.js');
var frontendRuntime = require('frontend-runtime')(localConfig);
var config          = frontendRuntime.config;
var app             = require('./lib/utils/devServer.js');

var bodyParser = require('body-parser');

app.use(bodyParser.json({limit: 10 * 1024 * 1024}));
app.use(bodyParser.raw({limit: 10 * 1024 * 1024}));
app.use(bodyParser.text({limit: 10 * 1024 * 1024}));
app.use(bodyParser.urlencoded({limit: 10 * 1024 * 1024, extended: true}));

app.use('/some-url', proxy(config.apiEndpointHost, {
  forwardPath: function(req, res) {
    return '/api2' + url.parse(req.url).path;
  }
}));

app.listen(config.portProxy);
console.log('Server started');

正如你所看到的,我为bodyParser传递'limit'参数(我希望上传文件),但它没有用 - 当我尝试上传1.5 Mb大小的图像时,我收到了错误:“stderr:error : 请求的实体太大”。我该如何解决?谢谢!

1 个答案:

答案 0 :(得分:2)

根据this issue,您不需要bodyParser

app.use('/some-url', proxy(config.apiEndpointHost, {
      limit: 10 * 1024 * 1024,
      forwardPath: function(req, res) {
        return '/api2' + url.parse(req.url).path;
      }
    }));