-1

I'm working on a Spring Boot Backend, with a React Frontend. Locally the request comes from a different URL than the Backend (localhost:3000 to localhost:8080). Due to that, I need a Cross Origin Configuration. For simplicity, I just allowed for localhost:3000 all API's. Yet still some request get blocked.

Here is my configuration:

    @Bean
    CorsConfigurationSource corsConfigurationSource() {
        CorsConfiguration configuration = new CorsConfiguration();
        configuration.setAllowedOrigins(Arrays.asList("http://localhost:3000", "http://localhost:3001"));
        configuration.setAllowedMethods(Arrays.asList("GET","POST", "PUT", "DELETE"));
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", configuration);
        source.registerCorsConfiguration("/user/login", configuration);
        return source;
    }

Here is the error, Firefox throws: CORS error

Any help would be appreciated :)

NoelHug
  • 21
  • 3

1 Answers1

-1

I found the fix for my problem with this StackOverflow post: https://stackoverflow.com/a/43559288/19465843

I'm just leaving my question up, so someone with the same problem, can find an answer more easily.

NoelHug
  • 21
  • 3