I built a backend with Spring and now I want to build a frontend with React. When I try to fetch my request URL I get the following error:
Access to fetch at 'http://localhost:8080/demo/getAll' from origin 'http://localhost:3000' has been blocked by CORS policy: 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.
Here is my code:
const fetchItems = async () => {
fetch('http://localhost:8080/demo/getAll').then(response => response.json()).then(data =>
console.log(data));
};
Does anyone know what the problem is and how do I fix it?