/cors-server

A server to add CORS headers to a proxied request.

Primary LanguageJavaScript

CORS-Anywhere Server

CORS-Anywhere is a Node.js package that adds CORS headers to a proxied request. This is useful when the API provider does not natively support CORS. Without altering the headers, a request to such a provider would cause an error and prevent the request from being fulfilled.

Tip: You can test out the server in this repo locally by using ports 3000 or 5000 in your application and prepending one of the proxy URLs listed below to your API request like this. You can also test your API endpoints with cors-server in the remote environment here. If you want to host your own server, follow the steps in the Implementation section below.

Proxy URLs

Below are the URLs that can be used for local testing on ports 3000 or 5000.

Firebase: https://proxy-ibmasyzzya-uc.a.run.app/

Fly.io: https://cors-server.fly.dev/

Implementation

The server can be implemented in one of four ways. Is is recommended to use Firebase or Fly.io.

Firebase

Navigate to the functions directory and follow the steps within the README.md therein. This is one of the recommended implementations.

Fly.io

Navigate to the fly.io directory and follow the steps within the README.md therein. This is one of the recommended implementations.

Heroku

Navigate to the heroku directory and follow the steps within the README.md therein. Note that Heroku has withdrawn provision of free dynos as of 28th of November 2022. The cost is now $5 for 1,000 dyno hours per month on the Eco plan that can be used across multiple apps. If this is your only Heroku project, then a potentially much cheaper option is the Basic plan that is only 1¢ per hour. This is billed on a pro rata basis, so you only pay when the server is active. Even if on 24/7, this would only be $7 per month.

Railway

Navigate to the railway directory and follow the steps within the README.md therein. Unfortunately the free monthly allowance gets reached after 500 hours (about 21 days) under the free Trial plan, so best to go with one of the other options.