CORS Anywhere

After a recent domain change at my workplace one of the API endpoints became inaccessible due to some configuration problems resulting in incorrect behavior in regards to cross-origin resource sharing policy. It interfered with one non-critical function of the website and was a bit of a nuisances but not big enough for back-end team to prioritize fixing it.

Thankfully, one of my colleagues from the front-end team discovered a workaround the issue which I was not aware of before. Apparently, there is a service called CORS Anywhere which is a simple API that enables cross-origin requests to anywhere. It works by proxying requests to these sites via a server.

Thus, all you have to do to work around CORS is to prepend the URL you want to access with and spoof an origin header. For example, instead of writing axios.get('') you would write as below:

    method: 'get',
    url: '',
    headers: {'Origin': ''}

This makes a call to with origin header set to the one that satisfies CORS policy requirements, and returns us the result. Simple yet elegant solution.

If you don’t want to rely on a 3rd party, you can also set up CORS Anywhere on your machine using npm module cors-anywhere. Of course, at this stage you may just as well set up your own proxy on your backend but if for whatever reason you don’t want to do that, keep this option in mind.

What do you think?

I hope you have got, how to use CORS Anywhere. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.

Leave a Reply