1. 程式人生 > >zuul 跨域訪問問題解決

zuul 跨域訪問問題解決

在gateway專案啟動類中加入以下程式碼

@Bean
public CorsFilter corsFilter() {
    final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
    final CorsConfiguration config = new CorsConfiguration();
    config.setAllowCredentials(true);
    config.addAllowedOrigin("*");
    config.addAllowedHeader("*"
); config.addAllowedMethod("*"); config.setMaxAge(18000L); source.registerCorsConfiguration("/**", config); return new CorsFilter(source); }