0

Using corporate network to call the REST API but always facing 'Access-Control-Allow-Origin' issues. Please find below the proxy.config.js to enable the CORS. And I am using sample daily weather report api to generate the Line Chart. Please find below the API. I have attached the screenshot too, could you please help me to resolve the issue.

https://samples.openweathermap.org/data/2.5/forecast/daily?id=524901&appid=b1b15e88fa797225412429c1c50c122a1

var HttpsProxyAgent = require('https-proxy-agent');
var proxyConfig = [{
  context: '/',
  target: 'https://samples.openweathermap.org',
  secure: false
}];

function setupForCorporateProxy(proxyConfig) {
  var proxyServer = process.env.http_proxy || process.env.HTTP_PROXY;
  if (proxyServer) {
    var agent = new HttpsProxyAgent(proxyServer);
    console.log('Using corporate proxy server: ' + proxyServer);
    proxyConfig.forEach(function(entry) {
      entry.agent = agent;
    });
  }
  return proxyConfig;
}

module.exports = setupForCorporateProxy(proxyConfig);

enter image description here

jps
  • 20,041
  • 15
  • 75
  • 79
Shiva
  • 1
  • 1
  • 1
    REF: https://stackoverflow.com/questions/37172928/angular-cli-server-how-to-proxy-api-requests-to-another-server. Add changeOrigin: true to proxy config. – sashwat May 14 '18 at 07:40

1 Answers1

-1

Activate Your CORS Plugin to avoid Access-Control-Allow-Origin error