简体   繁体   English

当请求主体 json 太重时,ExpressJS CORS 错误

[英]ExpressJS CORS error when req body json is too heavy

I have an expressJS server receiving API requests from a React APP front-end.我有一个 expressJS 服务器从 React APP 前端接收 API 请求。

Anytime I push a request with an image less than 200Kb;每当我推送图片小于 200Kb 的请求时; it goes through as expected.它按预期进行。 But when the image parameter is exceeding 200Kb I get a CORS error.但是当图像参数超过 200Kb 时,我会收到 CORS 错误。

CORS error if file exceed 200Kb如果文件超过 200Kb,则 CORS 错误

My setup for CORS and bodyParser size params:我对 CORS 和 bodyParser 大小参数的设置:

app.use(bodyParser.json({limit: "50mb"}));
app.use(bodyParser.urlencoded({limit: "50mb", extended: true, parameterLimit:50000}));
app.use(cors());

I'm stuck on this.我坚持这一点。 Any help would be much appreciated;)任何帮助将非常感激;)

I just change from我只是从

app.use(bodyParser.json({limit: "50mb"}));

to

app.use(express.json({limit: "50mb"}));

I'm not sure what's the big difference here;我不确定这里有什么大区别。 but that solved my issue.但这解决了我的问题。 Still it's really annoying that the size limit results into CORS error.尺寸限制导致 CORS 错误仍然很烦人。 Not really friendly to debug:/对调试不是很友好:/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM