Setting Axios Header to Java Backend based on value stored in express session #5955
Unanswered
NikhilNanjappa
asked this question in
Q&A
Replies: 1 comment
-
Hi, it's been almost a year, but how about setting the headers on axios client creation on your first line? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a node.js express (server-side rendering) frontend app that calls java backend endpoints. I use Axios to call the java endpoints. I need to set a header named "agent-id" into every request express makes to java, the value of that header comes from the express session (
req.session
).My Axios code is on another module. I'm importing that module and calling my APIs.
Currently my Axios module code is setup like so:
and I call my APIs from frontend express app like so:
What I've tried
I tried updating req.headers using a app.use middleware but I could not find that header within the axios interceptor.
Ideally I dont want to change my entire API calling structure by passing req obj on every existing API calls, so is there anyway I can globally set the header using express session value for every Java request ?
Beta Was this translation helpful? Give feedback.
All reactions