[英]request entity too large error when using oas3-tools package,openapi 3.0 in node.js
index.js file index.js 文件
'use strict'; '使用严格';
var path = require('path');
var http = require('http');
var cors = require('cors');
var oas3Tools = require('oas3-tools');
require("dotenv").config({ path: ".env" });
console.log(`### Running on ~~~ ${process.env.Instance} ~~~ ENV ###`);
var serverPort = 8080;
function validate(request, scopes, schema) {
// security stuff here
return true;
}
// swaggerRouter configuration
var options = {
routing: {
controllers: path.join(__dirname, './controllers')
},
logging: {
format: 'combined',
errorLimit: 400
},
};
var expressAppConfig = oas3Tools.expressAppConfig(
path.join(__dirname, "./api/openapi.yaml"),
options
);
expressAppConfig.addValidator();
var app = expressAppConfig.getApp();
app.use(cors());
var json2xls = require('json2xls');
app.use(json2xls.middleware);
// Initialize the Swagger middleware
http.createServer(app).listen(serverPort, function () {
});
// Connect to database
var mongo = require("./utils/db");
----------------------------------------EOF---------------------------------------------- --------------------------------------EOF-------- ------------------------------------
PFB the version of the tools which we've used. PFB 我们使用的工具版本。 "express": "^4.17.1", "oas3-tools": "2.1.3"
“快递”:“^ 4.17.1”,“oas3工具”:“2.1.3”
I've tried body-parser and app.use(express.json({limit:'25mb'})).我试过 body-parser 和 app.use(express.json({limit:'25mb'}))。 But nothing resolved the request entity too large error.
但是没有解决请求实体太大的错误。 It would be great if anyone suggest me any different solution.
如果有人建议我任何不同的解决方案,那就太好了。
This works for me:这对我有用:
app._router.stack = app._router.stack.filter((i) => i.name !== 'jsonParser');
app.use(bodyParser.json({ limit: 5 * 1024 * 1024 }));
You can see all the middleware in app._router.stack which is populated by expressAppConfig function (express.app.config.js).您可以在 app._router.stack 中看到所有中间件,它由 expressAppConfig function (express.app.config.js) 填充。
I found out when you use bodyParser.json(), it will add another middleware layer to that stack - but from my observation, express will use the first one.我发现当你使用 bodyParser.json() 时,它会向该堆栈添加另一个中间件层 - 但根据我的观察,express 将使用第一个。 That's why I removed all jsonParser before setting the limit.
这就是我在设置限制之前删除所有 jsonParser 的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.