The specs of fetch() mentioned using fetch() this way:
fetch("https://pk.example/berlin-calling.json", {mode:"cors"})
.then(res => {
if(res.headers.get("content-type") &&
res.headers.get("content-type").toLowerCase().indexOf("application/json") >= 0) {
return res.json()
} else {
throw new TypeError()
}
}).then(processJSON)
This is the first time I see {mode:"cors"}
and the specs says the default is: {mode:"no-cors"}
, but not using it works well:
Demo: https://codesandbox.io/s/lucid-leaf-y9v25?file=/src/App.js
Why is that we don't use {mode:"cors"}
and it still works cross origin?