diff --git a/changelog.md b/changelog.md index 2d68b2e1..aec515d3 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,9 @@ # changelog +## 3.1.4 + +- 优化跨域 + ## 3.1.3 - 修复监控日志乱码问题 diff --git a/sop-auth/pom.xml b/sop-auth/pom.xml index caac5511..0e0b19ec 100644 --- a/sop-auth/pom.xml +++ b/sop-auth/pom.xml @@ -26,7 +26,7 @@ com.gitee.sop sop-service-common - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT diff --git a/sop-common/pom.xml b/sop-common/pom.xml index 8f357c77..aa568688 100644 --- a/sop-common/pom.xml +++ b/sop-common/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.gitee.sop sop-common - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT pom diff --git a/sop-common/sop-bridge-gateway/pom.xml b/sop-common/sop-bridge-gateway/pom.xml index 2034d181..de573072 100644 --- a/sop-common/sop-bridge-gateway/pom.xml +++ b/sop-common/sop-bridge-gateway/pom.xml @@ -5,11 +5,11 @@ sop-common com.gitee.sop - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT ../pom.xml 4.0.0 - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT sop-bridge-gateway @@ -17,7 +17,7 @@ com.gitee.sop sop-gateway-common - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT diff --git a/sop-common/sop-bridge-zuul/pom.xml b/sop-common/sop-bridge-zuul/pom.xml index aee68506..4767f2c5 100644 --- a/sop-common/sop-bridge-zuul/pom.xml +++ b/sop-common/sop-bridge-zuul/pom.xml @@ -5,11 +5,11 @@ sop-common com.gitee.sop - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT ../pom.xml 4.0.0 - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT sop-bridge-zuul @@ -17,7 +17,7 @@ com.gitee.sop sop-gateway-common - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT diff --git a/sop-common/sop-gateway-common/pom.xml b/sop-common/sop-gateway-common/pom.xml index fc76d072..afc79b01 100644 --- a/sop-common/sop-gateway-common/pom.xml +++ b/sop-common/sop-gateway-common/pom.xml @@ -5,11 +5,11 @@ com.gitee.sop sop-common - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT ../pom.xml sop-gateway-common - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT jar sop-gateway-common diff --git a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/AbstractConfiguration.java b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/AbstractConfiguration.java index 45c15f21..41432203 100644 --- a/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/AbstractConfiguration.java +++ b/sop-common/sop-gateway-common/src/main/java/com/gitee/sop/gatewaycommon/manager/AbstractConfiguration.java @@ -3,10 +3,10 @@ package com.gitee.sop.gatewaycommon.manager; import com.gitee.sop.gatewaycommon.bean.ApiConfig; import com.gitee.sop.gatewaycommon.bean.ApiContext; import com.gitee.sop.gatewaycommon.bean.BeanInitializer; -import com.gitee.sop.gatewaycommon.interceptor.RouteInterceptor; import com.gitee.sop.gatewaycommon.bean.SpringContext; import com.gitee.sop.gatewaycommon.gateway.loadbalancer.NacosServerIntrospector; import com.gitee.sop.gatewaycommon.interceptor.MonitorRouteInterceptor; +import com.gitee.sop.gatewaycommon.interceptor.RouteInterceptor; import com.gitee.sop.gatewaycommon.limit.LimitManager; import com.gitee.sop.gatewaycommon.loadbalancer.SopPropertiesFactory; import com.gitee.sop.gatewaycommon.message.ErrorFactory; @@ -40,6 +40,7 @@ import org.springframework.context.event.EventListener; import org.springframework.core.env.Environment; import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.UrlBasedCorsConfigurationSource; +import org.springframework.web.cors.reactive.CorsWebFilter; import org.springframework.web.filter.CorsFilter; import javax.annotation.PostConstruct; @@ -184,11 +185,35 @@ public class AbstractConfiguration implements ApplicationContextAware, Applicati /** - * 跨域过滤器 + * 跨域过滤器,zuul */ @Bean + @ConditionalOnMissingBean + @ConditionalOnProperty("zuul.servlet-path") public CorsFilter corsFilter() { - return createCorsFilter(); + UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", createCorsConfiguration()); + return new CorsFilter(source); + } + + /** + * 跨域过滤器,gateway采用react形式,需要使用reactive包下的UrlBasedCorsConfigurationSource + */ + @Bean + @ConditionalOnMissingBean + @ConditionalOnProperty("sop.gateway-index-path") + public CorsWebFilter corsWebFilter() { + org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource source = new org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource(); + source.registerCorsConfiguration("/**", createCorsConfiguration()); + return new CorsWebFilter(source); + } + + private CorsConfiguration createCorsConfiguration() { + CorsConfiguration corsConfiguration = new CorsConfiguration(); + corsConfiguration.addAllowedOrigin("*"); + corsConfiguration.addAllowedHeader("*"); + corsConfiguration.addAllowedMethod("*"); + return corsConfiguration; } /** @@ -211,24 +236,6 @@ public class AbstractConfiguration implements ApplicationContextAware, Applicati return new EurekaServerIntrospector(); } - protected CorsFilter createCorsFilter() { - UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - this.registerCorsConfiguration(source); - return new CorsFilter(source); - } - - protected void registerCorsConfiguration(UrlBasedCorsConfigurationSource source) { - source.registerCorsConfiguration("/**", corsConfiguration()); - } - - protected CorsConfiguration corsConfiguration() { - CorsConfiguration corsConfiguration = new CorsConfiguration(); - corsConfiguration.addAllowedOrigin("*"); - corsConfiguration.addAllowedHeader("*"); - corsConfiguration.addAllowedMethod("*"); - return corsConfiguration; - } - @Override public void run(ApplicationArguments args) throws Exception { this.isStartupCompleted = true; diff --git a/sop-common/sop-service-common/pom.xml b/sop-common/sop-service-common/pom.xml index 8833f4f7..3f8df9ad 100644 --- a/sop-common/sop-service-common/pom.xml +++ b/sop-common/sop-service-common/pom.xml @@ -6,11 +6,11 @@ com.gitee.sop sop-common - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT ../pom.xml sop-service-common - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT jar sop-service-common diff --git a/sop-example/sop-book/sop-book-web/pom.xml b/sop-example/sop-book/sop-book-web/pom.xml index 021e4a65..72ec0b74 100644 --- a/sop-example/sop-book/sop-book-web/pom.xml +++ b/sop-example/sop-book/sop-book-web/pom.xml @@ -28,7 +28,7 @@ com.gitee.sop sop-service-common - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT com.gitee.sop diff --git a/sop-example/sop-easyopen/pom.xml b/sop-example/sop-easyopen/pom.xml index b1baeb38..f764ec77 100644 --- a/sop-example/sop-easyopen/pom.xml +++ b/sop-example/sop-easyopen/pom.xml @@ -29,7 +29,7 @@ com.gitee.sop sop-service-common - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT diff --git a/sop-example/sop-story/sop-story-web/pom.xml b/sop-example/sop-story/sop-story-web/pom.xml index 2eb38127..a3b47ac4 100644 --- a/sop-example/sop-story/sop-story-web/pom.xml +++ b/sop-example/sop-story/sop-story-web/pom.xml @@ -28,7 +28,7 @@ com.gitee.sop sop-service-common - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT com.gitee.sop diff --git a/sop-gateway/pom.xml b/sop-gateway/pom.xml index 8152cc6a..d55365e1 100644 --- a/sop-gateway/pom.xml +++ b/sop-gateway/pom.xml @@ -34,7 +34,7 @@ com.gitee.sop sop-bridge-gateway - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT diff --git a/sop-website/pom.xml b/sop-website/pom.xml index 37fc35b8..0fc10980 100644 --- a/sop-website/pom.xml +++ b/sop-website/pom.xml @@ -35,7 +35,7 @@ com.gitee.sop sop-gateway-common - 3.1.3-SNAPSHOT + 3.1.4-SNAPSHOT