https://github.com/harttle/auto-cors
A proxy to automatically add CORS headers
https://github.com/harttle/auto-cors
Last synced: 11 months ago
JSON representation
A proxy to automatically add CORS headers
- Host: GitHub
- URL: https://github.com/harttle/auto-cors
- Owner: harttle
- License: mit
- Created: 2022-05-25T06:29:43.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2022-08-14T17:08:31.000Z (almost 4 years ago)
- Last Synced: 2025-04-06T03:41:20.088Z (about 1 year ago)
- Language: JavaScript
- Size: 27.3 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# auto-cors
A proxy to automatically add CORS headers, supports:
- Simple requests with `Access-Control-Allow-Origin: "*"`
- OPTIONS preflight request for non-simple requests.
- CORS request with crendentials included.
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.
```javascript
// set a "Cookie: XXX" header when forwarding request
fetch(
"https://cors.harttle.com/https://example.com",
{
headers: {
"Auto-Cors-Request-Header-Cookie": "XXX"
}
}
)
```
## Install
```bash
npm i auto-cors
```
## Use in Node.js
```javascript
const cors = require("auto-cors")
const port = process.env.PORT || 8080;
cors.server.listen(port, () => {
console.log(`server listening to ${port}`);
});
```
Visit in your browser.
## Use in command line
```bash
npx auto-cors
```
The default port is 8080, use `AUTO_CORS_PORT` to set a different port, for example:
```bash
AUTO_CORS_PORT=9001 npx auto-cors
```
Visit in your browser.
## Deploy your own service
Install
```bash
# install globally
npm i -g auto-cors
auto-cors
# or use npx auto-cors
```
Here's a systemd script for auto-cors: