Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

239
Visualizações
Express: limit request size

To limit the request size to 123 bytes, I use the following which works fine:

app.use(bodyParser.urlencoded({
    extended: true,
    limit: 123
}));

To parse all requests except for "/specialRequest", I use the following which works fine as well:

app.use(/^(?!\/specialRequest)/,bodyParser.urlencoded({
    extended: true
}));

But I fail to limit the request size of all requests to 123 and parse all requests except for "/specialRequest". Here is my current code:

app.use(/^(?!\/specialRequest)/,bodyParser.urlencoded({
    extended: true,
    limit: 123
}));

However, this only limits the requests size for requests different than "/specialRequest". How can I limit the request size of all requests to 123 and parse all requests except for "/specialRequest"?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If you want the request body for /specialRequest to be limited in size but not parsed, you can use bodyParser.raw(). In that case, req.body will be a Buffer instance that contains the request body as-is (unparsed, although it will be inflated if it was presented as gzipped or deflated data; this behaviour can be disabled through its options).

You need to declare it before you insert the bodyParser.urlencoded() middleware:

app.post('/specialRequest', bodyParser.raw({ limit : 123, type : '*/*' }), function(req, res) {
  ...
});

app.use(bodyParser.urlencoded({
    extended: true,
    limit: 123
}));
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda