How to create a proxy server on Heroku
Tags: node, heroku, cors, proxy
Published: 2021-03-24 22:38:21

---
title: How to create a proxy server on Heroku
published: true
description: In this article, we are going to create our proxy CORS server hosting it on Heroku and having access to it anytime we need it instead of using the generally hosted public URL used by everyone, here on this URL, https://cors-anywhere.herokuapp.com/
tags: Node, Heroku, cors, proxy
cover_image: https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i05x361w8nbz3pwe0i27.jpeg
---

## The Cross-Origin Resource Sharing (CORS) Error

Have you encountered this error?

![Screen Shot 2020-08-07 at 00.40.44.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1596757387324/lL0H-uduJ.png)

This error occurs when working with APIs in your application code, and these bugs creep up every time you try to call the origin from another URL. The CORS errors stem from a security mechanism that the browser implements called the same-origin policy. 

In this article, we will create our proxy CORS server hosting it on Heroku and have access to it any time we need it instead of using the generally hosted public URL used by everyone here on this with this [link](https://cors-anywhere.herokuapp.com/).

## Prerequisites
We will need the following to be installed on our system to begin.

- Install the Heroku CLI. 
For macOS, you can use homebrew. Visit [heroku-cli](https://devcenter.heroku.com/articles/heroku-cli) for installation guides for your respective OS.

- Install Node. Visit [nodejs](http://nodejs.org/) for installation guides. 

- Basic git version control skills


## Step by Step guideline on creating a proxy server

- Clone this [repository](https://github.com/Rob--W/cors-anywhere/) to our local machine.

![Screen Shot 2020-08-07 at 01.40.29.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1596760856202/q8GeWJJr3.png)

- **cd** into the cloned repository and run **npm install** to install on the dependencies for the project.

- Log into Heroku from the terminal.

![Screen Shot 2020-08-07 at 01.44.16.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1596761185703/zS8I-ETA7.png)

After logging in from the terminal, follow the prompts from the opened browser to your Heroku account.
![Screen Shot 2020-08-07 at 01.47.19.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1596761307932/b4wcBhDZt.png)

- Create an app with the command **Heroku create**

![Screen Shot 2020-08-07 at 01.55.06.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1596761729994/Z5x0Uyogj.png)

After the app has been created and before deployment, Heroku will display a generic message with the deployed URL that you can use in place for the universal cors-anywhere URL. 

![Screen Shot 2020-08-07 at 01.58.42.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1596762680244/24adiFLMM.png)


- The last thing to do now is to push your newly created proxy server to Heroku

![Screen Shot 2020-08-07 at 02.13.13.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1596762809276/W0SYS71sH.png)


![Screen Shot 2020-08-07 at 02.14.04.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1596762902725/rbTjw6Igy.png)

## Conclusion

The CORS errors can be the bane of the frontend developer. But in this guide, we were able to spin up a proxy server from scratch using a Heroku server and basic git commands. 

With these fixes, you'll never have to break a sweat overseeing the red CORS error in your browser, and you can confidently now have an error-free connection as a frontend developer.

Here is a valuable resource related to CORS

[Fixing CORS](https://medium.com/@dtkatz/3-ways-to-fix-the-cors-error-and-how-access-control-allow-origin-works-d97d55946d9)