AvidDabbler Blog

CORS Life for Dummies

May 26, 2020

Introduction

So there are only so many times that you wish to come across the dreaded CORS error before you start thinking that there must be a better way. You come across cors-anywhere and think, “This is it!!! But how do do I deploy? Why aren’t the steps just out there?”

Well now thanks to a fed up novice web developer. You too can solve these errors in a snap with your own private cors-anywhere deployment.

Install Dependencies

So if you do not have the following I would recommend installing them before you get started.

The next thing that you are going to need to do is install heroku via npm. Run:

npm install heroku.

Deploy Cors-Anywhere

Go ahead and either fork and clone or just clone the cors-anywhere. Once you have have the repo cloned on your machine you can deploy to Heroku in 2 steps. First open up your cli and go to the cloned directory then run:

git push heroku master

If this is your first time working with Heroku you are going to need to sign up for a free account and then sign-in.

If deployed correctly you should be able to go to the Heroku dashboard and find your cors-anywhere application

Configuring Cors-Anywhere

Once you have deployed and have it up and running you should be able to get to the options by going to the application > settings and then scroll down to config vars and click reveal config vars.

reveal config vars

Right now there are 2 different variables that I have set up for my project:

  • RATELIMIT - This sets up the amount of default requests can be made it take 3 different variables. Number of requests, reset of ratelimit, and a space separated list of exempt sites.
  • WHITELIST - This is the master list of URL’s that you are allowed to use this application.

whitelist and ratelimit

LINKS!!!


Written by Walter Jenkins who lives and works in Saint Louis. His passions are Civic Tech, Smart Cities and Alternative Transportation. He specializes in working with data analysis and visualization through maps.
You should follow him on Twitter.