简体   繁体   English

Node.js:拒绝太大的请求,然后再处理

[英]Nodejs: Decline too large requests before they are processed

I am running into this error using express and bodyparser module: PayloadTooLargeError: request entity too large . 我正在使用express和bodyparser模块PayloadTooLargeError: request entity too large此错误: PayloadTooLargeError: request entity too large

Now, I don't care if these requests are declined. 现在,我不在乎这些请求是否被拒绝。 The problem is that my server seems to be blocked for a few seconds until it "processed" the too large request and recognizes that its too large. 问题是我的服务器似乎被阻塞了几秒钟,直到它“处理”了太大的请求并意识到它太大。

So is there a way for me to tell NodeJS to just ignore these requests altogether (surely you can see the file size in the request headers somewhere)? 因此,有没有办法让我告诉NodeJS完全忽略这些请求(确保您可以在某处的请求标头中看到文件大小)?

Could you please try using limit with bodyParser there with express ? 您可以尝试在带有express bodyParser使用limit吗?

For example: 例如:

app.use(bodyParser.json({limit: '10mb'}));
app.use(bodyParser.urlencoded({limit: '10mb', extended: true}));

Of course you have to require the body-parser module first. 当然,您必须首先require body-parser模块。

Also there is an additional parameterLimit you can set on the second line. 此外,您还可以在第二行中设置其他parameterLimit Hope this works for you :) 希望这对你有用:)

app.use(bodyParser.urlencoded({
    limit: '10mb', 
    extended: true, 
    parameterLimit: 10000
});

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

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