Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/imjacobclark/cors-container
A CORS proxy in a container (Docker) for when you need to `Access-Control-Allow-Origin: *`!
https://github.com/imjacobclark/cors-container
cors cors-proxy docker permissive-cors
Last synced: 5 days ago
JSON representation
A CORS proxy in a container (Docker) for when you need to `Access-Control-Allow-Origin: *`!
- Host: GitHub
- URL: https://github.com/imjacobclark/cors-container
- Owner: imjacobclark
- License: mit
- Created: 2016-03-07T15:55:04.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-23T23:00:55.000Z (almost 2 years ago)
- Last Synced: 2024-08-01T12:33:33.204Z (3 months ago)
- Topics: cors, cors-proxy, docker, permissive-cors
- Language: JavaScript
- Homepage: https://cors-container.herokuapp.com
- Size: 259 KB
- Stars: 190
- Watchers: 5
- Forks: 35
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-starred - imjacobclark/cors-container - A CORS proxy in a container (Docker) for when you need to `Access-Control-Allow-Origin: *`! (docker)
README
# cors-container
A CORS proxy in a container (Docker) for when you need to `Access-Control-Allow-Origin: *`!
[![Build Status](https://travis-ci.org/imjacobclark/cors-container.svg)](https://travis-ci.org/imjacobclark/cors-container)
[![Docker Pulls](https://img.shields.io/docker/pulls/imjacobclark/cors-container.svg)](https://hub.docker.com/r/imjacobclark/cors-container/)You can use CORS Container without running it yourself via Heroku (it's on a free tier dyno, so initial startup time may be slow!) [https://cors-container.herokuapp.com](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](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 origional 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 runinnng 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 `` would be modified to `` 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-cotainer if you want relative URLs rewriting.
## Deploying
### Docker(hub)
```bash
$ docker pull imjacobclark/cors-container
$ docker run --restart=always -d -p 3000:3000 --name cors-container imjacobclark/cors-container
```### Docker(source)
```shell
$ git pull https://github.com/imjacobclark/cors-container.git && cd cors-container
$ docker build -t cors-container .
$ docker run --restart=always -d -p 3000:3000 --name cors-container cors-container
```### Node
```shell
$ git pull https://github.com/imjacobclark/cors-container.git && cd cors-container
$ npm run test && npm start
```## Thanks to
* [Express](http://expressjs.com/)
* [request-promise](https://github.com/request/request-promise)
* [rel-to-abs](https://github.com/auth0/rel-to-abs)
* [Supertest](https://github.com/visionmedia/supertest)
* [Mocha](http://mochajs.org/)
* [Nock](https://github.com/pgte/nock)