lunes, 12 de diciembre de 2022

3 Ways to Fix the CORS Error — and How the Access-Control-Allow-Origin Header Works

 https://medium.com/@dtkatz/3-ways-to-fix-the-cors-error-and-how-access-control-allow-origin-works-d97d55946d9

3 Ways to Fix the CORS Error — and How the Access-Control-Allow-Origin Header Works

The Cors Error

Fix one: install the Allow-Control-Allow-Origin plugin

But the plugin fix is deceiving

Why was the CORS error there in the first place?

How does the same-origin policy work under the hood?

Origin: http://localhost:3000
Access-Control-Allow-Origin: http://localhost:3000
Access-Control-Allow-Origin: *

Did the plugin “fix” it?

Fix two: send your request to a proxy

Fix three: build your own proxy

If you want to see this in action, head to the source code for the above, along with relevant steps in the README: https://github.com/15Dkatz/beat-cors-server

Conclusion

Connect with David

No hay comentarios:

Publicar un comentario