Setup a Node.js CORS Proxy with Caching Support

Hon Nam
The Startup
Published in
5 min readJan 17, 2021

--

Photo by Sigmund on Unsplash
CORS Error accessing https://bloomberg.com from another domain

If you’ve ever built a web app that had to request data from a different domain, you’ve probably had to wrap your head around the browser’s same-origin policy and Cross-Origin Resource Sharing (CORS).

If our app is hosted under a certain domain (e.g. webapp.com), and it tries to make a request to an API that lives under a different domain (e.g. anotherdomain.com), then the browser's same-origin policy kicks in and blocks the request.

CORS is a feature that allows the owner of anotherdomain.com to tell the browser that if it is cool for other domains to make requests to it. When our frontend makes requests to a backend owned by another person, we’ll have to deal with CORS, as well as any request rate limiting policy imposed by the destination servers.

In this article, we’ll build an proxy server that will allows us to retrieve data from any servers bypassing CORS, as well as implement response caching to supercharge response times & avoid the problem of requests being rate-limited.

Building the Caching Proxy Server

Architecture

--

--

Hon Nam
The Startup

I strive to unlock new possibilities everyday.