|
|
@ -8,6 +8,8 @@ import io.sc.platform.mvc.service.FrontEndService; |
|
|
import io.sc.platform.util.UrlUtil; |
|
|
import io.sc.platform.util.UrlUtil; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
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.stereotype.Service; |
|
|
import org.springframework.util.StringUtils; |
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
@ -19,10 +21,14 @@ import java.util.HashMap; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
import java.util.concurrent.TimeUnit; |
|
|
|
|
|
import java.util.regex.Matcher; |
|
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
@Service("io.sc.platform.mvc.service.impl.FrontEndServiceImpl") |
|
|
@Service("io.sc.platform.mvc.service.impl.FrontEndServiceImpl") |
|
|
public class FrontEndServiceImpl implements FrontEndService { |
|
|
public class FrontEndServiceImpl implements FrontEndService { |
|
|
private static final Logger log = LoggerFactory.getLogger(FrontEndServiceImpl.class); |
|
|
private static final Logger log = LoggerFactory.getLogger(FrontEndServiceImpl.class); |
|
|
|
|
|
|
|
|
|
|
|
@Autowired private Environment environment; |
|
|
/** |
|
|
/** |
|
|
* 本地前端模块 Map |
|
|
* 本地前端模块 Map |
|
|
* key: 模块名称 |
|
|
* key: 模块名称 |
|
|
@ -97,7 +103,7 @@ public class FrontEndServiceImpl implements FrontEndService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private String getRemoteEntryUrlPrefix(FrontEndModule frontEndModule,HttpServletRequest request) { |
|
|
private String getRemoteEntryUrlPrefix(FrontEndModule frontEndModule,HttpServletRequest request) { |
|
|
String protocol =null; |
|
|
String protocol ="http"; |
|
|
String host =null; |
|
|
String host =null; |
|
|
int port =80; |
|
|
int port =80; |
|
|
String contextPath =null; |
|
|
String contextPath =null; |
|
|
@ -108,19 +114,25 @@ public class FrontEndServiceImpl implements FrontEndService { |
|
|
log.error("",e); |
|
|
log.error("",e); |
|
|
} |
|
|
} |
|
|
if(requestUrl!=null){ |
|
|
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(); |
|
|
host =StringUtils.hasText(frontEndModule.getHost())?frontEndModule.getHost():requestUrl.getHost(); |
|
|
port =frontEndModule.getPort()!=null?frontEndModule.getPort():requestUrl.getPort(); |
|
|
port =frontEndModule.getPort()!=null?frontEndModule.getPort():requestUrl.getPort(); |
|
|
}else{ |
|
|
}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(); |
|
|
host =StringUtils.hasText(frontEndModule.getHost())?frontEndModule.getHost():request.getLocalAddr(); |
|
|
port =frontEndModule.getPort()!=null?frontEndModule.getPort():request.getLocalPort(); |
|
|
port =frontEndModule.getPort()!=null?frontEndModule.getPort():request.getLocalPort(); |
|
|
} |
|
|
} |
|
|
if(protocol.toUpperCase().startsWith("HTTPS")){ |
|
|
|
|
|
protocol ="https"; |
|
|
//通过请求 URL 规则判断是否采用 HTTPS
|
|
|
}else { |
|
|
String matcherString =environment.getProperty("appplication.frontend.remoteEntry.protocol.https.matcher.url",String.class,""); |
|
|
protocol = "http"; |
|
|
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(); |
|
|
contextPath =StringUtils.hasText(frontEndModule.getContextPath())?frontEndModule.getContextPath():request.getContextPath(); |
|
|
|
|
|
|
|
|
StringBuilder sb =new StringBuilder(); |
|
|
StringBuilder sb =new StringBuilder(); |
|
|
|