A simple CORS proxy server with configurable allowed domains.
- Install
node
curl https://webi.sh/node | sh source ~/.config/envman/PATH.env
- Download and enter the project directory
git clone https://github.com/dashhive/cors-server.js pushd ./cors-server.js/
- Run
cors-server
with config options# ./bin/cors-server.js [flags] ./bin/cors-server.js --prefix /api/cors/ --port 2677 --domains 'example.com, example.org'
- Test with
curl
(browser testing requires https, see below)curl http://localhost:2677/api/cors/example.com
You can either set command line flags, or set ENVs. Flags take precedence.
flag | ENV | example | description |
---|---|---|---|
--port | PORT= | 2677 | Number |
--prefix | CORS_PROXY_PREFIX= | /api/cors/ | URL Path |
--domains | CORS_ALLOWED_DOMAINS= | 'example.com, example.org' | URL Hostname |
See ./example.env
for config options.
- Install
caddy
curl https://webi.sh/caddy | sh source ~/.config/envman/PATH.env
- Create
./Caddyfile
https://localhost:443 { handle /api/* { reverse_proxy localhost:2677 } }
- Run caddy and localhost https will be generated
caddy run --config ./Caddyfile
- Open the JavaScript console
Cmd ⌘ + Alt ⌥ + I - Test it out with
fetch
await fetch("https://localhost/api/cors/example.com/", { mode: "cors" });
- Install Serviceman
curl https://webi.sh/serviceman | sh source ~/.config/envman/PATH.env
- Generate and enable service file for
cors-server
sudo env PATH="$PATH" \ serviceman add --system -- \ ./bin/cors-server.js -- --port 2677 \ --prefix /api/cors/ \ --domains example.com
- Generate and enable service file for
caddy
sudo env PATH="$PATH" \ serviceman add --system --cap-net-bind -- \ caddy run --config ./Caddyfile