I have a react based frontend and a spring backend (which uses spring security). I have disabled CORS in the spring security configuration (at least I think so) but the requests still gives this error:
Access to XMLHttpRequest at 'http://localhost:8080/api/v1/registration/' 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.
This is the frontend:
const register = () => {
//var url = process.env.REACT_APP_SERVER_IP + "/api/v1/registration";
var url = "http://localhost:8080/api/v1/registration/";
var userData = {
email: "test@test.com",
username: "uname",
password: "pass"
}
axios.post("http://localhost:8080/api/v1/registration/", userData
).then(function (response) {
alert(response);
}).catch(function (error) {
alert(error);
});
}
This is the backend:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and().csrf().disable()
.authorizeRequests()
.antMatchers("/api/v*/registration/**")
.permitAll()
.anyRequest()
.authenticated().and()
.formLogin();
}
Any idea as to why requests are still blocked?