0

Im trying to fetch a endpoint from my Electron app with this code:

componentDidMount() {
        fetch("https://xxxxxxxx.xxx/getCheckouts?licenseKey=XXX-XXX-XXX", {
            mode: 'no-cors'
            method: 'GET',
            headers: {
                "X-Api-Key": "XXXXXXXXXXX",
                'content-type': 'application/json'
            }
        })
        .then(res => res.json())
        .then(data => {
            
            console.log(data)
        })
        .catch((err)=>{
            console.error(err)
        })
    }

and i receive this error in the console:

Access to fetch at 'https://xxxxxxx.xxx/getCheckouts?licenseKey=XXX-XXX-XXX' from origin 'http://localhost:3000' 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. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

I cannot find a solution to this, any idea why this happen?

  • Usually a CORS issue is on the server side of things. Since you're hitting localhost:3000 I would suggest looking at your development server and see about setting it up using an npm package such as https://www.npmjs.com/package/cors – Chris Mar 29 '21 at 16:19
  • Make the request from your Main process and not your Renderer process. – Quentin Mar 29 '21 at 16:21

0 Answers0