无关风月
2024-11-04 64f7ccb9ef8b5a0618e65cddc14b981c1f108ba3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
//package com.xinquan.gateway.filter;
//
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.web.cors.CorsConfiguration;
//import org.springframework.web.cors.reactive.CorsWebFilter;
//import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;
//
//@Configuration
//public class FdmallCorsConfiguration {
//    /**
//     * 添加跨域过滤器
//     * @return
//     */
//    @Bean // 添加过滤器
//    public CorsWebFilter corsWebFilter(){
//        //基于url跨域,选择reactive包下的
//        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
//        // 跨域配置信息
//        CorsConfiguration configuration = new CorsConfiguration();
//        // 允许跨域的头
//        configuration.addAllowedHeader("*");
//        // 允许跨域的请求方式
//        configuration.addAllowedMethod("*");
//        // 允许跨域的请求来源
//        configuration.addAllowedOrigin("*");
//        // 是否允许携带cookie跨域
//        configuration.setAllowCredentials(true);
//        // 任意url都要进行跨域配置
//        source.registerCorsConfiguration("/**", configuration);
//        return new CorsWebFilter(source);
//    }
//}