Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

240
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda