Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

124
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!