-2

The CORS issue has been haunting for a while now. I know a couple of solutions:

1) CORS: * ( not recommended)

2) Creating a proxy for API calls.

I am looking for some other simpler solutions. I know this might be a duplicate thread/question but things have evolved and I am hoping to get another solution to this.

PS: I am using Angular as frontend framework.

ABGR
  • 4,052
  • 2
  • 19
  • 42
  • 1
    Why do you think proxy is not a simpler solution? It works pretty amazing with minimal configurations. – ABGR Jun 06 '20 at 14:20
  • 1
    If you are making calls to a third party API, there's nothing you can do about CORS issues, as CORS is a server-side security feature to prevent undesired requests. If the API is returning a CORS error, perhaps you aren't supposed to be calling it... – Will Alexander Jun 06 '20 at 14:21
  • You can't use your own CORS headers. You'd have to convince the *third party* involved to do it to their servers themselves. – Pointy Jun 06 '20 at 14:27
  • "I know this might be a duplicate thread/question but things have evolved" — Don't ask duplicate questions. [Issue a bounty](https://stackoverflow.com/help/bounty) to draw new attention to an existing question if you think the answers are insufficient. – Quentin Jun 06 '20 at 14:32
  • I know proxy.conf.json in angular is simpler to use, but we can use it only with ng serve. Is there a way we can configure the file for ng build --prod.? – Rajnish Mishra Jun 07 '20 at 16:50

1 Answers1

-1

Apart from the ones that you mentioned, another solution to deal with CORS is, using third-party proxy URLs that you can append to your API url calls.

For e,g,

var proxy = https://cors-anywhere.herokuapp.com/;
var url = proxy + "http://example.com" //now make your http request with this.

The downside of using a third-party proxy URL is you have to rely on them. In case, they're down, you won't be able to make requests.

I think proxy is way more preferred if you're working on Angular and this is how I dealt with it when I faced this problem: https://stackoverflow.com/a/44537898/4650975

ABGR
  • 4,052
  • 2
  • 19
  • 42