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

529
Visualizações
express middleware to modify requests

i currently have a running server using nodejs, mongo, express and W2UI for the front end. W2ui requests come in an a record array that has all the parameters record[name]:foo i want to write a middleware that edits requests and changes them before they reach the route.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can create your own middleware to manipulate the request. I've created a middleware that adds current server time to the request like this

var addDate = function(req, res, next) {
  req.body.date = new Date();
  next();
}

Now, I can use this middleware for all requests like this:

app.use(addDate);

or to a spesific route like this

app.get('/', addDate, function(req, res) {
  res.send(req.body);
});

The response from the get request will be

{
  "date": "2017-01-31T11:46:37.003Z"
}
over 4 years ago · Santiago Trujillo Relatório

0

You can do this in http.js, create a function to modify request in a way you want and then give it in order array like below : -

order: [
  'startRequestTimer',
  'cookieParser',
  'session',
  'bodyParser',
  'xframe',
  'handleBodyParserError',
  '**myRequestLogger**',
  'compress',
  'methodOverride',
  // 'poweredBy',
  '$custom',
  'router',
  'ravenRequestHandler',
  'ravenErrorHandler',
  'www',
  'favicon',
  '404',
  '500'
],

myrequestLogger is a function to log the request here.

over 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