TypeError: Failed to fetch in React using Fetch API

701 Views Asked by At

I using React and I am creating an application that integrates the backend as well. I am trying to fetch data from my backend. I have started both the frontend and the backend, and, using Thunderclient, checked that the endpoint is working fine. But whenever I am trying to fetch the same data using a fetch API call, I get the following error:

Image

Here is the code snippet for the same.

const getNotes = async () => {
    const response = await fetch(`${host}/api/notes/fetchall`, {
        method: "GET", 
        headers: {
            'Content-Type': 'application/json',
            "authtoken" : "xxxxxxxxxxxxxxxxxxxxxxxxxx"
        },
    });
    // ...
}

Can someone help me out with this?

CORS has been installed and used in index.js for the backend. I also tried using "mode": "CORS" but even that is not working for me.

0

There are 0 best solutions below