DEV Community

Cover image for CORS Reverse Proxy (cors-reverse-proxy)

Posted on • Updated on

CORS Reverse Proxy (cors-reverse-proxy)

Use Case

  1. For local development environment etc.
  2. When you want to load resources (images, JS, etc.) while trusting a specific web application.


I wanted a docker image that would add a simple Access-Control-Allow-Origin: * header.

In addition, when I searched on the Internet, I could not find a reverse proxy that suits my purpose so much.
So I made it while enjoying and studying the GO language.

When doing web development, there are times when content loading is blocked due to CORS policy issues. If you have seen the following message in the developer console, I think that you have it.

... has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

It's very correct, and it may be a necessary protection for security, but there are times when you do not want to be blocked after judging that there is no problem in development

As a workaround, there are 2 patterns

  1. A case where Access-Control-Allow-Origin: * Header is added by nginx or Apache
  2. Install the CORS related package to the middleware of the application and set it

There is a way to create a config file such as nginx or Apache and pass it as a container, but in the first place it is troublesome to prepare a config file just to give Access-Control-Allow-Origin: * Header.

So I developed this project.

Top comments (0)