XHR is working fine but Fetch API causing CORS error

Viewed 1480

I am starting to build a Reactjs app that uses Fetch API for my requests to my Web API. I wasn't having any issues until I set up Microsoft authentication for my Azure application and now my requests throw a CORS error.

To troubleshoot where the issue might be, I set up the same request using XHR. I was able to complete the requests with no problem. I was wondering if anyone would be able to tell me where I am going wrong?

XHR Version

var oReq = new XMLHttpRequest();  
oReq.open('get', 'https://myazureapp.azurewebsites.net/api/user', true);  
oReq.send();

Fetch API Version

fetch('https://myazureapp.azurewebsites.net/api/user');

Here is my error:

No 'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'https://myazureapp.azurewebsites.net' is therefore
not allowed access. If an opaque response serves your needs, set the
request's mode to 'no-cors' to fetch the resource with CORS disabled.

Any insight on what I might be doing wrong would be great. Please let me know if you need any more information, and I will update my question accordingly.

0 Answers
Related