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?