CORS Error when trying to hit web API

Hello,

I’m trying to hit my SonarQube container’s web API from a React app and am getting:

“Access to XMLHttpRequest at … has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.”

Does anyone know how to fix this? Thank you

Hi,

Can you provide the call you’re making (redacted as necessary) that’s getting this error response?

 
Ann

Sure. I actually got it to work by putting both my react app and the SonarQube container behind a reverse proxy so that they could both be called using localhost:8080. The API call was authenticated properly after I logged into SonarQube, and I stopped receiving the CORS error. But I’d be interested in hearing of other potential solutions / suggestions as well. This is the call:

  const { data } = await axios.get(
    "http://localhost:8080/api/issues/search?componentKeys=my_app&resolved=false"
  );

Hi,

You should be able to make that call from anywhere, so I guess the error was on your React app side…?

 
Ann