snippetjavascriptTip
What is CORS?
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:
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:
- The protocol (e.g.
httporhttps) - The hostname (e.g.
30secondsofcode.org) - The port (e.g.
80or3000)
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.
80or3000)
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.organdhttps://www.30secondsofcode.org(different protocols)http://www.30secondsofcode.organdhttp://dev.30secondsofcode.org(different hostnames)https://30secondsofcode.organdhttps://30secondsofcode.org:3000(different ports)
Context
From 30-seconds-of-code: cors-explained
Revisions (0)
No revisions yet.