0

I am currently working on a React SPA which is going to retrieve data from an HTTP-triggered Azure Functions. When running on my dev machine I am having issues with CORS and I'm not sure how to remedy that. I do so in the Azure Portal where there are options to enable CORS but I'm not sure how to replicate those locally.

Code:

const response = await axios.get('http://localhost:7071/api/jobs', {
    headers: {
      'Content-Type': 'application/json',
    },
  });

Error:

Access to XMLHttpRequest at 'http://localhost:7071/api/jobs' from origin 'https://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I've already attempted to follow the following steps to add the CORS headers in .vs/--project--/config/applicationhost.config, but it did not fix the problem: https://davidsekar.com/asp-net/cors-development-in-localhost

Mike Cole
  • 14,474
  • 28
  • 114
  • 194

0 Answers0