From 760adf0f6dff0b6b3cd7f117faac23fb3413859a Mon Sep 17 00:00:00 2001 From: tanghc Date: Tue, 26 May 2020 10:02:22 +0800 Subject: [PATCH 1/3] 3.1.3 --- .../manager/AbstractConfiguration.java | 49 +++++++++++-------- 1 file changed, 28 insertions(+), 21 deletions(-) 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..3a784093 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 + */ + @Bean + @ConditionalOnMissingBean + @ConditionalOnProperty("sop.gateway-index-path") + public CorsWebFilter corsFilterReact() { + 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; From 44f55063757032dc246f091802651de2310b12a4 Mon Sep 17 00:00:00 2001 From: tanghc Date: Tue, 26 May 2020 10:04:27 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=B7=A8=E5=9F=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sop/gatewaycommon/manager/AbstractConfiguration.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 3a784093..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 @@ -197,12 +197,12 @@ public class AbstractConfiguration implements ApplicationContextAware, Applicati } /** - * 跨域过滤器,gateway + * 跨域过滤器,gateway采用react形式,需要使用reactive包下的UrlBasedCorsConfigurationSource */ @Bean @ConditionalOnMissingBean @ConditionalOnProperty("sop.gateway-index-path") - public CorsWebFilter corsFilterReact() { + public CorsWebFilter corsWebFilter() { org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource source = new org.springframework.web.cors.reactive.UrlBasedCorsConfigurationSource(); source.registerCorsConfiguration("/**", createCorsConfiguration()); return new CorsWebFilter(source); From 5f9bab580734c18baf6b6bbeb2bb5ff473d73312 Mon Sep 17 00:00:00 2001 From: tanghc Date: Tue, 26 May 2020 10:05:19 +0800 Subject: [PATCH 3/3] 3.1.4 --- changelog.md | 4 ++++ sop-auth/pom.xml | 2 +- sop-common/pom.xml | 2 +- sop-common/sop-bridge-gateway/pom.xml | 6 +++--- sop-common/sop-bridge-zuul/pom.xml | 6 +++--- sop-common/sop-gateway-common/pom.xml | 4 ++-- sop-common/sop-service-common/pom.xml | 4 ++-- sop-example/sop-book/sop-book-web/pom.xml | 2 +- sop-example/sop-easyopen/pom.xml | 2 +- sop-example/sop-springmvc/pom.xml | 2 +- sop-example/sop-story/sop-story-web/pom.xml | 2 +- sop-gateway/pom.xml | 2 +- sop-website/pom.xml | 2 +- 13 files changed, 22 insertions(+), 18 deletions(-) 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 93b8adc3..f1bf6fa5 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-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 a0be69c8..2c9a35aa 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 5ab9efd2..0a8ba7b7 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 23215698..cd1f93c3 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 49238e63..ebd8d9d5 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 38fa1e3f..8a602362 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