A proxy to automatically add CORS headers
MIT License
A proxy to automatically add CORS headers, supports:
Access-Control-Allow-Origin: "*"
There's an auto-cors
service deployed at cors.harttle.com. Both HTTP and HTTPS are supported:
Additional headers:
Auto-Cors-Request-Header
to set additional request headers that are not allowed (like cookie
, referer
, origin
, etc.) in headers. e.g.
// set a "Cookie: XXX" header when forwarding request
fetch(
"https://cors.harttle.com/https://example.com",
{
headers: {
"Auto-Cors-Request-Header-Cookie": "XXX"
}
}
)
npm i auto-cors
const cors = require("auto-cors")
const port = process.env.PORT || 8080;
cors.server.listen(port, () => {
console.log(`server listening to ${port}`);
});
Visit http://localhost:8080/https://example.com in your browser.
npx auto-cors
The default port is 8080, use AUTO_CORS_PORT
to set a different port, for example:
AUTO_CORS_PORT=9001 npx auto-cors
Visit http://localhost:9001/https://example.com in your browser.
Install
# install globally
npm i -g auto-cors
auto-cors
# or use npx auto-cors
Here's a systemd script for auto-cors:
https://gist.github.com/harttle/a801084f42b9ee1a2aa6bf5c191b9ad9