Skip to content

Commit 6d5f80e

Browse files
author
Taois
committed
fix: 修复hostName获取错误导致的关姐地址异常
1 parent de056c2 commit 6d5f80e

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

utils/file.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,21 @@ export function getParsesDict(host) {
148148
const jx_conf_text = readFileSync(jx_conf, 'utf-8');
149149
let jx_conf_content = jx_conf_text.trim();
150150

151-
// 准备模板变量字典
151+
let hostName = host;
152+
try {
153+
if (typeof host === 'string' && host) {
154+
const u = new URL(host.includes('://') ? host : `http://${host}`);
155+
hostName = u.hostname || host;
156+
}
157+
} catch (e) {
158+
const withoutProto = String(host || '').replace(/^[a-zA-Z]+:\/\//, '');
159+
const withoutPath = withoutProto.split('/')[0];
160+
hostName = withoutPath.includes(':') ? withoutPath.split(':')[0] : withoutPath;
161+
}
162+
152163
let var_dict = {
153164
host,
154-
hostName: host.split(':').length > 1 ? host.slice(0, host.lastIndexOf(":")) : host
165+
hostName
155166
};
156167

157168
// 使用Jinja模板引擎渲染配置内容
@@ -213,4 +224,4 @@ export function executeParse(name, host, url) {
213224
}
214225

215226
globalThis.pathLib = pathLib;
216-
globalThis.executeParse = executeParse;
227+
globalThis.executeParse = executeParse;

0 commit comments

Comments
 (0)