|
|
@@ -2,7 +2,6 @@ package com.sundot.airport.framework.config;
|
|
2
|
2
|
|
|
3
|
3
|
import javax.servlet.http.HttpServletRequest;
|
|
4
|
4
|
|
|
5
|
|
-import cn.hutool.core.util.StrUtil;
|
|
6
|
5
|
import org.springframework.stereotype.Component;
|
|
7
|
6
|
import com.sundot.airport.common.utils.ServletUtils;
|
|
8
|
7
|
|
|
|
@@ -25,24 +24,10 @@ public class ServerConfig {
|
|
25
|
24
|
|
|
26
|
25
|
public static String getDomain(HttpServletRequest request) {
|
|
27
|
26
|
StringBuffer url = request.getRequestURL();
|
|
28
|
|
- String contextPath = request.getServletContext().getContextPath();
|
|
|
27
|
+ String contextPath = request.getContextPath();
|
|
|
28
|
+ // 删除请求URI部分,保留基础URL
|
|
29
|
29
|
url.delete(url.length() - request.getRequestURI().length(), url.length());
|
|
30
|
|
-
|
|
31
|
|
- // 如果 URL 以 / 结尾,去掉它(避免出现 http://example.com/:9011)
|
|
32
|
|
- if (url.charAt(url.length() - 1) == '/') {
|
|
33
|
|
- url.deleteCharAt(url.length() - 1);
|
|
34
|
|
- }
|
|
35
|
|
- // 获取当前请求的端口
|
|
36
|
|
- int currentPort = request.getServerPort();
|
|
37
|
|
- // 如果是80或443端口(HTTP/HTTPS默认端口),则强制使用9011端口
|
|
38
|
|
- if (!StrUtil.equals("http://192.168.3.221", url) && (currentPort == 80 || currentPort == 443)) {
|
|
39
|
|
- int protocolEnd = url.indexOf("://") + 3;
|
|
40
|
|
- int portStart = url.indexOf(":", protocolEnd);
|
|
41
|
|
- if (portStart < 0) {
|
|
42
|
|
- // 没有端口,添加端口
|
|
43
|
|
- url.insert(url.length(), ":9011");
|
|
44
|
|
- }
|
|
45
|
|
- }
|
|
|
30
|
+ // 直接返回基础URL + 上下文路径,完全保留原始端口
|
|
46
|
31
|
return url.append(contextPath).toString();
|
|
47
|
32
|
}
|
|
48
|
33
|
}
|