Sign inSign up

saschabrockel/cors-container

By saschabrockel

•Updated about 4 years ago

A CORS proxy in a container (Docker) for when you need to Access-Control-Allow-Origin: *!

Image
0

50K+

saschabrockel/cors-container repository overview

⁠cors-container

A CORS proxy in a container (Docker) for when you need to Access-Control-Allow-Origin: *!

This project is not implemented by myself. Originally the repo is https://github.com/imjacobclark/cors-container⁠.

You can use CORS Container without running it yourself via Heroku (it's on a free tier dyno, so the initial startup time may be slow!) https://cors-container.herokuapp.com⁠.

⁠About

If you need permissive CORS for a front-end project, simply deploy this container and proxy your HTTP requests through it.

Once the container is running, you may navigate to http://container-address:3000/https://jacobclark.xyz⁠, cors-container will then proxy the specified resource and transform the original headers to be CORS permissive, whilst keeping original headers in-tact.

If you intend to use this in production over the open web, ensure the service is locked down with restrictive firewall/access permissions, otherwise any content may be proxied over your server.

I suggest implementing proper CORS headers on your resources and using this for development purposes only.

⁠Relative URL rewriting

cors-container can rewrite relative URLs to full URLs of the response body you have proxied.

For example, if we wish to proxy http://blog.jacobclark.xyz/ and cors-container is running on http://localhost:3000/ the request URL would be http://localhost:3000/http://blog.jacobclark.xyz/.

cors-container will rewrite any relative URLs it finds in the proxies response body. For example <a href="/css/style.css"> would be modified to <a href="http://localhost:3000/http://blog.jacobclark.xyz/css/style.css"> in the proxied response.

This can be useful if you wish to be able to pull additional assets on a page through the proxy such as stylesheets and JavaScript.

This is not enabled by default as this option mutates the original response body.

Set rewrite-urls in the request header to cors-container if you want relative URLs rewriting.

⁠Deploying

⁠Docker(hub)
$ docker run --restart=always -d -p 3000:3000 --name cors-container saschabrockel/cors-container:latest

Or as compose file:

version: '3.3'
services:
  cors-container:
    restart: always
    ports:
      - 3000:3000
    container_name: cors-container
    image: saschabrockel/cors-container:latest

⁠Thanks to

Tag summary

Content type

Image

Digest

sha256:dd6e28487…

Size

49.7 MB

Last updated

about 4 years ago

docker pull saschabrockel/cors-container