You see this is what happen, the client side has a cookie with http only flag and inside of it a JWT that will be use by the API server to authorize the request , the thing is that the JWT should be in a Authorization header so I am using a middle server to catch the client request, extract the JWT from the cookie, set the Authorization Header within client request and then forward the request to the API server to fetch the data.
The main problem is that I dont know how properly set the header from the middle server or even if that is posible, because every time I try to forward to the API server this last got the Authorization header undefined that I supposedly set in the middleware server.
So, how can I set a Authorization Header and forward to another server properly?, the middle server and the API server both uses NodeJS and Express.
This is so far the code from the middle server I have (dont worry about the cookie extraction part, this is just testing propuses):
const proxy = require('express-http-proxy');
const express = require('express');
const cors = require('cors');
const app = express();
const PORT = 8083;
app.use(cors());
// app.use(express.json());
app.use('/graphql',
(req, res, next) => {
req.headers['Authorization'] = `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZFVzZXIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkphY2sifQ.5y3IhB4i_THfKZr5BYe6dZruhOUbQt7SRT_rrssApCo`;
next()
},
proxy('http://localhost:8081/graphql'));
app.listen(PORT, () => console.log(`http://localhost:${PORT}`));