前端从网关进行调用,跨域问题解决
This commit is contained in:
@@ -8,9 +8,10 @@ import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
/**
|
||||
* 全局跨域配置
|
||||
* 注意:前端从网关进行调用时不需要配置
|
||||
* Created by macro on 2019/7/27.
|
||||
*/
|
||||
@Configuration
|
||||
//@Configuration
|
||||
public class GlobalCorsConfig {
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.macro.mall.config;
|
||||
|
||||
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;
|
||||
import org.springframework.web.util.pattern.PathPatternParser;
|
||||
|
||||
/**
|
||||
* 全局跨域配置
|
||||
* 注意:前端从网关进行调用时需要配置
|
||||
* Created by macro on 2019/7/27.
|
||||
*/
|
||||
@Configuration
|
||||
public class GlobalCorsConfig {
|
||||
|
||||
@Bean
|
||||
public CorsWebFilter corsFilter() {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
config.addAllowedMethod("*");
|
||||
config.addAllowedOrigin("*");
|
||||
config.addAllowedHeader("*");
|
||||
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(new PathPatternParser());
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
|
||||
return new CorsWebFilter(source);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user