package com.kakarote.gateway.config;

import org.springframework.context.annotation.Bean;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.cors.reactive.CorsWebFilter;
import org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource;

/**
 * @author Zenas
 */
public class CorsConfig {
    @Bean
    public CorsWebFilter corsWebFilter() {
        CorsConfiguration corsConfig = new CorsConfiguration();
        corsConfig.addAllowedOrigin("http://crm.topxuetang.com"); // 允许的域
        corsConfig.addAllowedMethod("*"); // 允许所有请求方法
        corsConfig.addAllowedHeader("*"); // 允许所有请求头
        corsConfig.setAllowCredentials(true); // 允许凭据

        UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
        source.registerCorsConfiguration("/**", corsConfig); // 对所有路径生效

        return new CorsWebFilter(source);
    }
}
