I'm using http-proxy-middleware
to setup request proxy from auth service to secured API.
Here I need to add custom header with authenticated user auth ID for every incoming request to the authentication layer. But with following implementation header not adding to the request. Here I've used on.proxyReq,
app.use('/info', auth, createProxyMiddleware({
target: process.env.BASE_API_URL,
changeOrigin: false,
on: {
proxyReq: (proxyReq, req, res) => {
console.log(`On Proxy Request ${proxyReq}`);
proxyReq.setHeader('x-auth-user', 'b05ff410-fbba-11ec-bfce-ddefb9f79237');
},
proxyRes: (proxyRes, req, res) => {
console.log(`On Proxy Response ${proxyRes}`);
},
error: (err, req, res) => {
console.log(`On Error Request ${err}`);
},
},
}));