A simple CORS proxy server with configurable allowed domains.
- Install
nodecurl 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-serverwith 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
caddycurl https://webi.sh/caddy | sh source ~/.config/envman/PATH.env
- Create
./Caddyfilehttps://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
fetchawait 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-serversudo env PATH="$PATH" \ serviceman add --system -- \ ./bin/cors-server.js -- --port 2677 \ --prefix /api/cors/ \ --domains example.com - Generate and enable service file for
caddysudo env PATH="$PATH" \ serviceman add --system --cap-net-bind -- \ caddy run --config ./Caddyfile