react code to fetch api data
getData = () => {
const url = FormatUrl(`/cluster`)
fetch(url, {
method: 'GET',
headers: new Headers({
'Authorization': 'Basic my_token',
'Content-Type': 'application/x-www-form-urlencoded'
})})
.then(res => res.json())
.then(res => {
console.log(res, "=")
})
}
error:
Access to fetch at 'https://beta.cnox.io:3001/cluster' from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response.
beta.cnox.io:3001/cluster:1 Failed to load resource: net::ERR_FAILED
Here i am trying to fetch data from above api and sending token also but getting below error. Same api is working from angular. please take a look