0

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.

  • Not enough information. Any errors in your network console on the response? Or is simply the header not there? – MikeOne Aug 12 '22 at 20:11
  • While calling HTTPS api from PCF we are getting error as [HPM] Error occurred while proxying request wbuiurl/v1/users to https://wbproxyapi.apps-np.xxx.com/ [EPROTO] (https://nodejs.org/api/errors.html#errors_common_system_errors) if I replace https with http the api calls are successful. – Vinod Kumar Marupu Aug 14 '22 at 10:32
  • It is not working on pcf. No issue with local host. The pcf team suggested us to pass the corporate proxies. But if I try to pass corporate proxies I'm getting error as can't set headers after they sent. – Vinod Kumar Marupu Aug 14 '22 at 10:36

0 Answers0