CORS Router in Express

Introduction

There are a few things that I seem to write over and over again, and as such, I am going to start to record them here, so I don’t have to!

CORS is a security mechanism that does not allow cross-domain communication from the browser, usually by default.  It can become a little tedious when developing locally and accessing servers that are also not running locally.  There are a few options for dealing with this:

  1. Temporarily disable CORS in the browser.
  2. Add headers to your services (if possible) to allow CORS.
  3. Write a router that adds headers and forwards the requests on and routes the responses back.

I’m going for option 3 this time. Continue reading