0

I have application using Spring on backend which have 5 microservices. Communication is dealing using REST and entering Cloud Gateway every time. Now I need to connect my React UI application with my backed. To resolve it, I need to configure CORS at my Cloud Gateway service. I have already tried to do something like this, but nothing helps (seems like it is not visible or configured wrongly).

@Configuration
public class CorsConfig extends CorsConfiguration {

    @Bean
    public CorsWebFilter corsFilter() {
        CorsConfiguration corsConfiguration = new CorsConfiguration();
        corsConfiguration.setAllowCredentials(true);
        corsConfiguration.addAllowedOrigin("*");
        corsConfiguration.setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE", "OPTIONS", "HEAD"));
        corsConfiguration.addAllowedHeader("origin");
        corsConfiguration.addAllowedHeader("content-type");
        corsConfiguration.addAllowedHeader("accept");
        corsConfiguration.addAllowedHeader("authorization");
        corsConfiguration.addAllowedHeader("cookie");
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", corsConfiguration);
        return new CorsWebFilter(source);
    }
}

Maybe I should configure it in another way? Another place?

zzzzz
  • 222
  • 2
  • 7
  • `CorsWebFilter` is part of the spring `reactive` packages and im guessing you are not building a `reactive` application. Please read the docs or one of the 1000s CORS questions that get asked every week on stack overflow https://stackoverflow.com/a/40431994/1840146 also in the future post your request and proper debuglogs when asking. There is so much information about CORS in spring out there that this question should not be needed. Downvoted lack of research – Toerktumlare Mar 11 '23 at 16:52

0 Answers0