Spring Cloud - Zuul Proxy is producing a No 'Access-Control-Allow-Origin' ajax response

后端 未结 6 588
别跟我提以往
别跟我提以往 2021-02-04 05:28

Startup Appplication:

@SpringBootApplication
@EnableZuulProxy
public class ZuulServer {

     public static void main(String[] args) {
         new SpringApplica         


        
6条回答
  •  误落风尘
    2021-02-04 06:16

    I had the same issue, and i have fixed by adding CorsFilter bean

      @Bean
      public FilterRegistrationBean corsFilter() {
        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        CorsConfiguration config = new CorsConfiguration();
        config.setAllowCredentials(true);
        config.addAllowedOrigin("*");
        config.addAllowedHeader("*");
        config.addAllowedMethod("*");
        source.registerCorsConfiguration("/**", config);
        FilterRegistrationBean bean = new FilterRegistrationBean(new CorsFilter(source));
        bean.setOrder(0);
        return bean;
      }
    

    And adding zuul's properties this code

    zuul:
      sensitiveHeaders:
      ignored-headers: Access-Control-Allow-Credentials, Access-Control-Allow-Origin
    

    You can find more detail about the issue here

提交回复
热议问题