使用公司网络调用REST API但始终面临“Access-Control-Allow-Origin”问题。请在下面找到proxy.config.js以启用CORS。我正在使用样本每日天气报告API来生成折线图。请在下面找到API。我也附上了截图,请你帮我解决这个问题。
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);
激活您的CORS插件以避免Access-Control-Allow-Origin错误