网关跨域配置
This commit is contained in:
parent
142a9a2456
commit
9d0103861f
|
|
@ -0,0 +1,32 @@
|
||||||
|
package com.tacit.gateway.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 java.util.Collections;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class CorsConfig {
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public CorsWebFilter corsWebFilter() {
|
||||||
|
CorsConfiguration corsConfig = new CorsConfiguration();
|
||||||
|
// 允许所有来源
|
||||||
|
corsConfig.addAllowedOriginPattern("*");
|
||||||
|
// 允许所有 HTTP方法
|
||||||
|
corsConfig.setAllowedMethods(Collections.singletonList("*"));
|
||||||
|
// 允许所有请求头
|
||||||
|
corsConfig.setAllowedHeaders(Collections.singletonList("*"));
|
||||||
|
// 允许携带凭证
|
||||||
|
corsConfig.setAllowCredentials(true);
|
||||||
|
|
||||||
|
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||||
|
// 对所有路径生效
|
||||||
|
source.registerCorsConfiguration("/**", corsConfig);
|
||||||
|
|
||||||
|
return new CorsWebFilter(source);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue