Sign inSign up

mathiasvda/simple-cors-proxy

By mathiasvda

•Updated 9 months ago

Image
0

789

mathiasvda/simple-cors-proxy repository overview

⁠🐳 Docker Simple CORS Proxy

🐳 Docker Image⁠

Based on: https://github.com/obeone/simple-cors-proxy⁠

This is a simple CORS proxy server. It allows you to make cross-origin requests to any API without worrying about CORS restrictions.

ā šŸš€ Features

  • 🌐 Seamless integration with external APIs
  • šŸ”’ Secure authentication using an API key
  • šŸ”— Ability to proxy requests to any URL using the X-Url-Destination header or directly in the URL path
  • šŸ”„ Handles CORS headers to enable cross-origin requests
  • āœˆļø Automatic preflight OPTIONS request handling (responds with 200 without proxying)
  • šŸ” Supports credentials with Access-Control-Allow-Credentials: true
  • āš™ļø Easy setup and configuration
  • 🐳 Docker image available for quick deployment

⁠🐳 Docker

You can use the Docker image to quickly run the proxy server. Here's how:

  1. Pull the Docker image:
docker pull mathiasvda/simple-cors-proxy
  1. Run the Docker container:
docker run -d --name simple-cors-proxy  -p 8080:8080 mathiasvda/simple-cors-proxy

⁠🐳 Docker Compose

You can use the Docker Compose file to quickly run the proxy server. Here's how:

  1. Run the Docker Compose file:
docker compose up -d

ā šŸ’» Manual Installation

To use this proxy server without Docker, follow these steps:

  1. Clone the repository:
git clone https://github.com/matdata-eu/simple-cors-proxy.git
  1. Install the dependencies:
npm install
  1. Start the server:
npm start
  1. The server will be running on port 8080 by default. You can change the port by setting the PORT environment variable.

ā šŸ“ Usage

⁠Basic Usage

To use the proxy server, you need to send a request with the X-Url-Destination header set to the URL of the resource you want to access.

Example:

curl -H "X-Url-Destination: http://example.com" http://localhost:8080/proxy
⁠Advanced Usage
⁠Passing URLs Directly

You can now pass the entire URL directly after /proxy/ in your request. This method preserves any query parameters that might be present in the URL.

Example:

curl http://localhost:8080/proxy/https://example.com/some/path?foo=1

By using this approach, the server automatically sets the X-Url-Destination header to the full decoded URL, making it easier and more intuitive to use the proxy.

⁠Authentication

If you need to authenticate access to the proxy server, you can use the PROXY_TOKEN environment variable. You set the PROXY_TOKEN environment variable to the value of your API key, and the proxy server will check the API key in the X-Proxy-Token header.

Example :

docker run -d --name simple-cors-proxy  -p 8080:8080 -e PROXY_TOKEN=YOUR_API_KEY mathiasvda/simple-cors-proxy
curl -H "X-Proxy-Token: YOUR_API_KEY" -H "X-Url-Destination: http://example.com" http://localhost:8080/proxy
⁠Headers Removal

If you need to remove some headers (for example X-Forwarded-For), you can use the x-headers-delete header. For example, if you want to remove the X-Forwarded-For header, you can set the x-headers-delete header to X-Forwarded-For.

You can also use the environment variable HEADERS_TO_DELETE to remove specific headers, or both.

In both cases, if you need to remove multiple headers, you can use a comma-separated list.

So for example :

docker run -d --name simple-cors-proxy  -p 8080:8080 -e HEADERS_TO_DELETE=X-Forwarded-For,X-Forwarded-Host mathiasvda/simple-cors-proxy
⁠Preflight OPTIONS Requests

The proxy server automatically handles preflight OPTIONS requests for all routes. When an OPTIONS request is received, the server responds with a 200 status code and the appropriate CORS headers without proxying the request to the destination server. This includes:

  • Access-Control-Allow-Origin: The origin from the request or *
  • Access-Control-Allow-Methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
  • Access-Control-Allow-Headers: X-Requested-With,Content-Type,Accept,Origin,Last-Modified,Authorization
  • Access-Control-Allow-Credentials: true
  • Access-Control-Max-Age: 86400 (24 hours)

This ensures smooth cross-origin requests from browsers without unnecessary round-trips to the destination server.

ā šŸ¤ Contributing

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request on GitHub⁠.

Generated by GPT-3.5-turbo-1106

Tag summary

Content type

Image

Digest

sha256:cea805527…

Size

80.8 MB

Last updated

9 months ago

docker pull mathiasvda/simple-cors-proxy