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

125
Visualizações
Request interceptors not modifying the value of request header in node js

I am using http-proxy-middleware to create a proxy and it's running successfully. Before calling app.use('/',proxy_options); I am trying to intercept my request and modifying the request header but updated value is not reflecting in headers.

app.use('/',(req,res,next)=>{
const token=getToken();
req.header['authorization']=token;
next();
});

Even I tried with req.header.authorization=token; and also without next();. When I am trying to print the my request header authorization:'' is coming as blank. Can any one let me know why this happening and how I can resolve this.

Any help or suggestions must be appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If your getToken() function is fetching token from other apis, then you should add await in front of it.

Try to use below code,

app.use('/', async (req,res,next)=>{
const token=await getToken();
req.headers['authorization']=token;
next();
});

You also need to replace header by headers, as mentioned above in code snippet.

It should work.

about 4 years ago · Juan Pablo Isaza 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