Two URLs have the same origin if the protocol, port (if specified), and host are the same for both. You may see this referenced as the "scheme/host/port tuple", or just "tuple".
The following table gives examples of origin comparisons with the URL http://store.company.com/dir/page.html
:
URL | Outcome | Reason |
---|---|---|
http://store.company.com/dir2/other.html |
Same origin | Only the path differs |
http://store.company.com/dir/inner/another.html |
Same origin | Only the path differs |
https://store.company.com/page.html |
Failure | Different protocol |
http://store.company.com:81/dir/page.html |
Failure | Different port (http:// is port 80 by default) |
http://news.company.com/dir/page.html |
Failure | Different host |
It will accept only the requests from the same PORT.
For example, http://www.example.com/abc
is the same origin as **http**://www.example.com/abcd
but not **https**://www.example.com/abcd
because the scheme is different.
The requests from the different PORTS are said to be cross origins.
By default, the servers follow Same Origin Policy.
To change this during development, we can allow the different PORTS to be accepted by the server using cors
package.
const cors=require("cors");
app.use(cors({
origin:[
"<http://localhost:8888>",
// add the origins as required
]
}));