CORS from anywhere

Have you ever struggled with CORS error messing up your website and just wanted to get it working? Thankfully, there is a service for that 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.