From 3c63853e90455142668c933272c7f6bd0c9b1d76 Mon Sep 17 00:00:00 2001 From: wangshaoping Date: Thu, 27 Nov 2025 12:29:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E6=A1=86=E6=9E=B6=E5=8F=91?= =?UTF-8?q?=E5=B8=83:=208.2.44=20=20=201)=20=E6=94=AF=E6=8C=81=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E8=BF=9C=E7=A8=8B=E5=85=A5=E5=8F=A3HTTPS=E5=8D=8F?= =?UTF-8?q?=E8=AE=AE=E7=9A=84=E9=85=8D=E7=BD=AE=E8=A7=84=E5=88=99=EF=BC=88?= =?UTF-8?q?=E6=AD=A3=E5=88=99=E8=A1=A8=E8=BE=BE=E5=BC=8F=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../mvc/service/impl/FrontEndServiceImpl.java | 26 ++++++++++++++----- .../plugins/application-properties.json | 3 +++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/gradle.properties b/gradle.properties index 4f27b9c3..182c89a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -37,7 +37,7 @@ application_version=1.0.0 # platform ########################################################### platform_group=io.sc -platform_version=8.2.43 +platform_version=8.2.44 platform_plugin_version=8.2.10 platform_core_frontend_version=8.2.137 diff --git a/io.sc.platform.mvc/src/main/java/io/sc/platform/mvc/service/impl/FrontEndServiceImpl.java b/io.sc.platform.mvc/src/main/java/io/sc/platform/mvc/service/impl/FrontEndServiceImpl.java index 3b738621..351a19d8 100644 --- a/io.sc.platform.mvc/src/main/java/io/sc/platform/mvc/service/impl/FrontEndServiceImpl.java +++ b/io.sc.platform.mvc/src/main/java/io/sc/platform/mvc/service/impl/FrontEndServiceImpl.java @@ -8,6 +8,8 @@ import io.sc.platform.mvc.service.FrontEndService; import io.sc.platform.util.UrlUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; @@ -19,10 +21,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +import java.util.regex.Matcher; +import java.util.regex.Pattern; @Service("io.sc.platform.mvc.service.impl.FrontEndServiceImpl") public class FrontEndServiceImpl implements FrontEndService { private static final Logger log = LoggerFactory.getLogger(FrontEndServiceImpl.class); + + @Autowired private Environment environment; /** * 本地前端模块 Map * key: 模块名称 @@ -97,7 +103,7 @@ public class FrontEndServiceImpl implements FrontEndService { } private String getRemoteEntryUrlPrefix(FrontEndModule frontEndModule,HttpServletRequest request) { - String protocol =null; + String protocol ="http"; String host =null; int port =80; String contextPath =null; @@ -108,19 +114,25 @@ public class FrontEndServiceImpl implements FrontEndService { log.error("",e); } if(requestUrl!=null){ - protocol =StringUtils.hasText(frontEndModule.getProtocol())?frontEndModule.getProtocol():requestUrl.getProtocol(); + //protocol =StringUtils.hasText(frontEndModule.getProtocol())?frontEndModule.getProtocol():requestUrl.getProtocol(); host =StringUtils.hasText(frontEndModule.getHost())?frontEndModule.getHost():requestUrl.getHost(); port =frontEndModule.getPort()!=null?frontEndModule.getPort():requestUrl.getPort(); }else{ - protocol =StringUtils.hasText(frontEndModule.getProtocol())?frontEndModule.getProtocol():request.getProtocol(); + //protocol =StringUtils.hasText(frontEndModule.getProtocol())?frontEndModule.getProtocol():request.getProtocol(); host =StringUtils.hasText(frontEndModule.getHost())?frontEndModule.getHost():request.getLocalAddr(); port =frontEndModule.getPort()!=null?frontEndModule.getPort():request.getLocalPort(); } - if(protocol.toUpperCase().startsWith("HTTPS")){ - protocol ="https"; - }else { - protocol = "http"; + + //通过请求 URL 规则判断是否采用 HTTPS + String matcherString =environment.getProperty("appplication.frontend.remoteEntry.protocol.https.matcher.url",String.class,""); + if(StringUtils.hasText(matcherString)){ + Pattern pattern =Pattern.compile(matcherString); + Matcher matcher =pattern.matcher(requestUrl.toString()); + if(matcher.find()){ + protocol ="https"; + } } + contextPath =StringUtils.hasText(frontEndModule.getContextPath())?frontEndModule.getContextPath():request.getContextPath(); StringBuilder sb =new StringBuilder(); diff --git a/io.sc.platform.mvc/src/main/resources/META-INF/platform/plugins/application-properties.json b/io.sc.platform.mvc/src/main/resources/META-INF/platform/plugins/application-properties.json index 2b126e99..cc069e8a 100644 --- a/io.sc.platform.mvc/src/main/resources/META-INF/platform/plugins/application-properties.json +++ b/io.sc.platform.mvc/src/main/resources/META-INF/platform/plugins/application-properties.json @@ -4,6 +4,9 @@ "order": 2000, "description": "spring.mvc configuration", "properties": [ + "# frontend remote entry url HTTPS protocol match pattern", + "appplication.frontend.remoteEntry.protocol.https.matcher.url = ", + "", "spring.mvc.async.request-timeout = 600000" ] },