HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavascriptTip

What is CORS?

Submitted by: @import:30-seconds-of-code··
0
Viewed 0 times
javascriptwhatcors

Problem

When it comes to HTTP, an origin is defined by several different aspects of a URL. As mentioned in a previous article, the origin is composed of the following:
  • The protocol (e.g. http or https)
  • The hostname (e.g. 30secondsofcode.org)
  • The port (e.g. 80 or 3000)


As long as all three of these match, the browser considers the two URLs to be same-origin. If any of these aspects differ, the browser considers the two URLs to be cross-origin. It might be helpful to look at some examples of different origins to clarify:

Solution


  • The hostname (e.g. 30secondsofcode.org)
  • The port (e.g. 80 or 3000)


As long as all three of these match, the browser considers the two URLs to be same-origin. If any of these aspects differ, the browser considers the two URLs to be cross-origin. It might be helpful to look at some examples of different origins to clarify:
  • http://30secondsofcode.org and https://www.30secondsofcode.org (different protocols)
  • http://www.30secondsofcode.org and http://dev.30secondsofcode.org (different hostnames)
  • https://30secondsofcode.org and https://30secondsofcode.org:3000 (different ports)

Context

From 30-seconds-of-code: cors-explained

Revisions (0)

No revisions yet.