feat(REQ-5965) - 结合容器环境返回完全的 url 地址

This commit is contained in:
wangli 2025-11-19 16:49:20 +08:00
parent 6b39b5e413
commit 9b1f366e05

View File

@ -70,10 +70,29 @@
<!-- 在<head>中添加通过Thymeleaf读取后端传递的环境变量推荐 -->
<script th:inline="javascript">
// 后端通过Model传递K8S服务名配置本地默认空K8S环境注入服务名
// 后端传递的基础路径K8Shttp://backend-service:8080本地
const apiBaseUrl = [[${apiBaseUrl}]] || '';
// 完整请求路径 = 基础路径 + 接口相对路径
const getFullUrl = (relativePath) => `${apiBaseUrl}${relativePath}`;
// 处理斜杠问题:移除路径首尾多余的斜杠,避免拼接后出现 //
const normalizePath = (path) => {
return path.replace(/^\/+|\/+$/g, ''); // 移除开头和结尾的斜杠
};
// 生成完整路径:确保 apiBaseUrl 和相对路径正确拼接
const getFullUrl = (relativePath) => {
if (!relativePath) return apiBaseUrl;
const normalizedBase = normalizePath(apiBaseUrl);
const normalizedRelative = normalizePath(relativePath);
// 若基础路径为空,直接返回相对路径(本地环境)
if (!normalizedBase) {
return `/${normalizedRelative}`;
}
// 拼接基础路径和相对路径K8S环境
return `${normalizedBase}/${normalizedRelative}`;
};
</script>
</head>
<body class="bg-gray-50 font-inter min-h-screen flex flex-col">
@ -558,7 +577,7 @@
try {
// 使用全局上下文路径变量拼接URL
const url = getFullUrl(`${ctx}web/process/get-auth-code?password=${encodeURIComponent(password)}`);
const url = getFullUrl(`web/process/get-auth-code?password=${encodeURIComponent(password)}`);
// 保持POST请求方式参数通过URL查询参数传递
const response = await fetch(url, {
@ -624,7 +643,7 @@
};
try {
const fullActionUrl = getFullUrl(this.action);
const fullActionUrl = getFullUrl("/web/process/handle");
// 使用全局上下文路径变量
const response = await fetch(fullActionUrl, {
method: this.method,