proxy.config.json usage - basics understanding

时间:2019-04-08 13:35:47

标签: angular cors

I use a remote service URL to retrieve data and use in my angular 6 project. Since it was producing CORS issue most times, I had to use proxy.config.json. Configuration is like below:

In angular.json, inside architect, inside serve, I gave an option like:

"proxyConfig":"proxy.config.json"

And inside proxy.config.json,

    {
     "/push/*":{
            "target":"https://abc.xyz.bluemix.net/",
            "secure":false,
            "logLevel":"debug",
            "changeOrigin":true

        }
}

While running in localhost, when any url with path as /push is visited, it automatically sets fetches data from url https://abc.xyz.bluemix.net/push/123

I need to know if there's a way to enable proxy on cloud too. Reason is that the application runs on https://sample-dev.bluemix.net due to which CORS issue occurs in absence of proxy.

The problem i face is that after these configurations, when i did a Build with a build cmd ng build --prod and push to cloud, when /push is visited, the response i get is the content in index.html and not the json data which am supposed to receive like how i received in local. I am thinking if it is due to directory structure.

Bottomnote: Enabling CORS headers in server end is not under my control. URLs are fake ones

1 个答案:

答案 0 :(得分:0)

proxy.config.json由开发服务器运行,如here所述。它不是下载到您的Web浏览器的任何内容。为了使代理工作,您必须在生产环境中运行开发服务器。 Angular提供了here所示的Apache配置参考,可帮助您配置到api后端的请求转发。

相关问题