Skip to content

A simple Node proxy to attach CORS headers to a response of a queried request to an endpoint.

License

Notifications You must be signed in to change notification settings

das-jishu/add-cors

Repository files navigation

add-cors

Add CORS cover image

Build Status License: MIT GitHub repo size Active Generic badge

Description: A Node proxy to add CORS headers to a request made to an API endpoint.

Image of error due to blockage by CORS policy

The image above shows a response blocked due to CORS policy not satisfied since correct headers were not present on the response. Frontend code won't have access to responses if responses don't have CORS headers embedded in it. If the backend server is owned by you, you can add the headers to solve the problem. If it isn't owned by you, a proxy server comes into play.

HOW TO USE

BASE URL: https://attach-cors.herokuapp.com/

Append the base URL infront of the API endpoint and perform the request as usual. The request will be passed through the proxy to get the response. CORS headers will be added to the response and sent back.

   fetch("some-API-with-no-CORS")                                    // ERROR
   fetch("https://attach-cors.herokuapp.com/some-API-with-no-cors")  // SUCCESS

Note that it is a public proxy with rate limiting applied, so responses might be delayed. A better approach would be to create your own proxy server to handle the requests. This can be done with the following commands:

   git clone https://github.com/das-jishu/add-cors.git
   cd add-cors/
   npm install
   heroku create cors-everywhere //cors-everywhere is an example. Use a unique name for heroku to create.
   git push heroku master

Prerequisites: Installing the Heroku CLI

After executing the above commands, your own server would be running and available at https://cors-everywhere.herokuapp.com/ You can make requests to endpoints simply by attaching the URL infront of it.

Example: https://cors-everywhere.herokuapp.com/http://www.check-cors.com

EXTRAS

Feel free to add any additional features by creating a pull request.

About

A simple Node proxy to attach CORS headers to a response of a queried request to an endpoint.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published