package com.ssyf.common.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 全局跨域
 * 无效情况说明：
 *  1. 在接口中使用HttpServletResponse直接返回数据的情况无效，这种情况请在接口中添加一下内容：
 *      response.addHeader("Access-Control-Allow-Origin", "*");
 *      response.addHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE");
 *      response.addHeader("Access-Control-Max-Age", "9600");
 *      response.addHeader("Access-Control-Allow-Headers", "x-requested-with");
 * @author huwei
 * @date 2022/8/17 9:47
 */
@Configuration(proxyBeanMethods = false)
public class CorsConfig {
    @Bean
    public WebMvcConfigurer corsConfigurer() {
        return new WebMvcConfigurer() {
            @Override
            public void addCorsMappings(CorsRegistry registry) {
                registry.addMapping("/**");
            }
        };
    }


}
