Browse Source

通过X-Forwarded-Host获取前端访问域名,X-Forwarded-Host在niginx配置文件中添加

multiwx
dy-hu 3 days ago
parent
commit
ad04c579b9
  1. 12
      cereshop-app/src/main/java/com/shop/cereshop/app/interceptor/AuthorizationInterceptor.java

12
cereshop-app/src/main/java/com/shop/cereshop/app/interceptor/AuthorizationInterceptor.java

@ -127,6 +127,7 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
//获取访问的二级域名 //获取访问的二级域名
String subDomain = getSubDomain(request); String subDomain = getSubDomain(request);
//log.info("前端访问域名: {}", subDomain);
if (ObjectUtil.isNotEmpty(subDomain)){ if (ObjectUtil.isNotEmpty(subDomain)){
//从商家设置的商城访问域名表中获取商家id即project //从商家设置的商城访问域名表中获取商家id即project
CerePlatformBusiness business = cerePlatformBusinessDAO.findByDomain(subDomain); CerePlatformBusiness business = cerePlatformBusinessDAO.findByDomain(subDomain);
@ -143,6 +144,8 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
project = "0"; project = "0";
} }
//log.info("商家project: {}", project);
//user存在 设置user //user存在 设置user
if(ObjectUtil.isNotNull(user)){ if(ObjectUtil.isNotNull(user)){
String userProject = user.getProject(); String userProject = user.getProject();
@ -206,12 +209,13 @@ public class AuthorizationInterceptor extends HandlerInterceptorAdapter {
*/ */
private String getSubDomain(HttpServletRequest request) { private String getSubDomain(HttpServletRequest request) {
//String host = request.getServerName(); //String host = request.getServerName();
String host = request.getHeader("Host");
String[] parts = host.split("\\.");
//String host = request.getHeader("Host");
String forwardedHost = request.getHeader("X-Forwarded-Host");
/* String[] parts = host.split("\\.");
if (parts.length >= 3){ if (parts.length >= 3){
return parts[0]; return parts[0];
}
}*/
return "";
return forwardedHost;
} }
} }
Loading…
Cancel
Save