I have a code to call proxy api from Angular using express server. While using the following code I'm getting error as can't set header after they sent. am I doing something wrong here?
const {createProxyMiddleware} = require('http-proxy-middleware');
const HttpsProxyAgent = require('https-proxy-agent');
const proxyServer = 'http://xyz:port';
const proxyOptions = {
target: targetUrl, // target host
pathRewrite: function(path) {
return path.replace('/api', '')
},
changeOrigin: true,
secure: false,
onProxyReq: function(proxyReq, req, res) {
const accessToken = req.accessToken.rawToken;
console.log("identityAccessToken", identityAccessToken);
proxyReq.setHeader('Authorization', `Bearer ${identityAccessToken}`);
},
agent: new HttpsProxyAgent(proxyServer)
}
thanks in advance.