0

this is my code:

fetch("https://api-2445582011268.apicast.io/games/",{
 method: 'GET',
 headers: {
  'user-key':'key',
  'Accept': 'application/json'
 }
})
.then(resp => resp.json())
.then(json => {
 console.log('json',json)
})

When I try to bring the data with the fetch I get the following error:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin .

and when I add "mode: 'no-cors'" it resolves and tried also to add the Access-Control-Allow-Origin but it did not fit anything, follow the same errors

fetch("https://api-2445582011268.apicast.io/games/",{
 method: 'GET',
 mode: 'no-cors', //here was added: mode:'no-cors '
 headers: {
  'user-key':'key',
  'Accept': 'application/json'
 }
})
.then(resp => resp.json())
.then(json => {
 console.log('json',json)
})

the independent if I add or not the mode: cors, I always get the following

error:
Authentication parameters missing
OPTIONS 403 (Forbidden)

Any idea of why?

Thanks in advance!

antzshrek
  • 9,276
  • 5
  • 26
  • 43
AndrexCode
  • 11
  • 1
  • 3
  • may be this will help https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe – Prasanna Nov 23 '17 at 05:33

1 Answers1

1

The api mentions that you'll need to create a back-end proxy due to CORS. You can use CORS Anywhere and prepend the proxy URL before the GET. After following this method I was able to pull the data successfully.

Credit goes to sideshowbarker from the following post.

https://stackoverflow.com/a/43268098/5491116

digitalh2o
  • 621
  • 5
  • 6