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

258
Vistas
How to post-process JSON response in express?

I am building an API with express and JSON middleware. I want to have a generic middleware that wraps each JSON response. The wrapping is an asynchronous process - there is a backend process that asynchronously generates a signature for the given JSON object. Example:

A route:

app.use("/", (req, res) => res.json({status: "ok"}))

The middleware would ideally intercept the JSON response, asynchronously generate a signature and ultimately send the user the following JSON:

{
    "signature": "...",
    "content": { "status": "ok" }
}

What's the best approach to building such a middleware?

I have tried replacing res.json with a custom function. The problem with this solution is that the signature generation is asynchronous, but the res.json is a synchronous function. This was my approach:

export function signatureMiddleware(req, res, next) {
    var json = res.json;
    res.json = async function (obj) {
      json.call(this, await wrapAndSign(obj));
    };
    next();
}
about 4 years ago · Santiago Gelvez
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