[Vuejs]-Trying to get my app posted on heroku got error :"No 'Access-Control-Allow-Origin' header is present on the requested resource"

0👍

Try this inside a WebSecurityConfigurerAdapter (worked for me)

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf()
            .disable()
            .cors()
    //....
    ;
}

@Bean
public CorsConfigurationSource corsConfigurationSource() {
    CorsConfiguration configuration = new CorsConfiguration();
    configuration.setMaxAge(Long.MAX_VALUE);
    configuration.setAllowCredentials(true);
    configuration.addAllowedHeader("*");
    configuration.addAllowedOrigin("*");
    configuration.addAllowedMethod("*");

    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    source.registerCorsConfiguration("/**", configuration);

    return source;
}

0👍

The Problem is from the backend, you need to enable cors on your backend server
please follow these steps from the official spring website :
https://spring.io/guides/gs/rest-service-cors/#_enabling_cors

Thank you and I hope this answer be useful

Leave a comment