All Projects → 15Dkatz → beat-cors-server

15Dkatz / beat-cors-server

Licence: other
Code for the "3 Ways to Fix the CORS Error — and How the Access-Control-Allow-Origin Header Works" article

Programming Languages

javascript
184084 projects - #8 most used programming language

Beat Cors Server

This project is an example of how to set up a proxy server to help frontends running in the browser beat the same origin policy.

The idea is to use express middleware to apply res.header('Access-Control-Allow-Origin', '*'); around requests to another server, with a more strict CORS setting.

That way, a server-to-server request could be completed, where the browser's same-origin policy would block it.

See the original article for a full walkthrough: https://medium.com/@dtkatz/3-ways-to-fix-the-cors-error-and-how-access-control-allow-origin-works-d97d55946d9z

Run the server

npm i
npm run start

Then visit localhost:3000/jokes/random.

Enjoy!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].