Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138163

CORS problem during PUT method (database update) in ReactJS & Spring Boot [duplicate]

$
0
0

When a database update (PUT method) is called from the Frontend application (from a JS file), the following error is obtained:


OPTIONS http://localhost:8080/administrator/update/2002?firstName=Nikola&lastName=Nikolic 403

Access to :3000/administratori:1 fetch at 'http://localhost:8080/administrator/update/2002?firstName=Nikola&lastName=Nikolic' 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.

Uncaught (in EditAdmin.js:52 promise) TypeError: Failed to fetch


When accessed through Postman, the database update (PUT method) works, however, from the Frontend application the database update (PUT method) doesnot work (the above problem occurs).

Previously, I included the org.springframework.web.cors.CorsConfiguration package within the SpringSecurityConfig class (in Backend based on Spring Boot), and the following code is added in the configure (HttpSecurity http) method :

http .cors().configurationSource(request -> new CorsConfiguration().applyPermitDefaultValues())...etc...

Also, the following code was added in the Fronted JS file within the PUT method in headers:

headers: { 'Authorization': 'Basic ' + window.btoa(this.props.username + ":" + this.props.password), 'Content-Type': 'application/json; charset=UTF-8' }

In package.json file I also added: "proxy": "http:localhost:8080"

Does anyone know the solution to this problem?

Thanks in advance


Viewing all articles
Browse latest Browse all 138163

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>