在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);
}
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐