CORS tutorial: guide to cross-origin resource sharing

Click for: original source

In this article you will learn all about Cross-Origin Resource Sharing, the circumstances under which it is needed, the benefits it provides, and how to configure a Node + Express application to support CORS. Written by Steve Hobbs.

Cross-Origin Resource Sharing (CORS) is a protocol that enables scripts running on a browser client to interact with resources from a different origin.

This is useful because, thanks to the same-origin policy followed by XMLHttpRequest and fetch, JavaScript can only make calls to URLs that live on the same origin as the location where the script is running.

Author then describes:

  • CORS - Why Is It Needed?
  • Identifying a CORS Response
  • Understanding CORS Request Types
  • How to Add CORS to a Nodejs Express App

You will also get code examples and learn how to alter a broken Node + Express application so that it accepted cross-origin requests, and could successfully make API calls to a backend running on a different origin. Nicely put together!

[Read More]

Tags nodejs javascript programming infosec