0

I created an api with spring boot and it's running on http://localhost:8080 but when trying to fetch data from it in react (running on localhost:5173) I'm getting this error :

"localhost/:1 Access to fetch at 'http://localhost:8080/api/songs' from origin 'http://localhost:5173' 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."

I tried adding http://locahost:8080 as a "proxy" in my package.json file but it still didn't work

I tried adding http://locahost:8080 as a "proxy" in my package.json file but it still didn't work

Priyen Mehta
  • 1,096
  • 1
  • 5
  • 19
  • Does this answer your question? [No 'Access-Control-Allow-Origin' header is present on the requested resource—when trying to get data from a REST API](https://stackoverflow.com/questions/43871637/no-access-control-allow-origin-header-is-present-on-the-requested-resource-whe) – P Fuster Feb 24 '23 at 10:11
  • Hello, this is a very common issue called CORS. There are a lot of answers covering this issue you can take a look in this site. You want to change your local server configuration and/or headers in your request in order to allow certain origins to fetch data. – P Fuster Feb 24 '23 at 10:12

0 Answers0