Skip to content

Commit 90f412c

Browse files
committed
fix: use URL format detection instead of string comparison for config injection
- Replace string comparison with URL format detection (http:// or https:// prefix) - This fixes the bug where sed global replacement would replace all placeholders, including those in condition checks, causing the condition to always evaluate to false - Now the code checks if apiBase starts with http:// or https:// to determine if it was replaced - All tests pass: replacement works correctly, unchanged placeholder is handled properly
1 parent 2e14044 commit 90f412c

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

web/index.html

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,16 @@
4343
window.__ROTE_CONFIG__ = {};
4444
}
4545
// 容器启动脚本会替换此占位符为实际的 API 基础 URL
46-
// 如果占位符未被替换(配置注入失败),删除该属性让代码回退到构建时配置
46+
// 注意:sed 全局替换会替换所有占位符,包括条件判断中的
47+
// 因此使用 URL 格式检测来判断是否被替换(有效的 API URL 以 http:// 或 https:// 开头)
4748
var apiBase = '__VITE_API_BASE_PLACEHOLDER__';
48-
if (apiBase !== '__VITE_API_BASE_PLACEHOLDER__') {
49+
// 检查是否是有效的 URL(以 http:// 或 https:// 开头)
50+
// 这样可以避免因为全局替换导致条件判断失效的问题
51+
if (
52+
apiBase &&
53+
typeof apiBase === 'string' &&
54+
(apiBase.indexOf('http://') === 0 || apiBase.indexOf('https://') === 0)
55+
) {
4956
window.__ROTE_CONFIG__.VITE_API_BASE = apiBase;
5057
}
5158
})();

0 commit comments

Comments
 (0)