@wendongfly/myhi 1.3.158 → 1.3.159
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/myhi.js +23 -0
- package/dist/index.js +1 -1
- package/dist/index.min.js +2 -2
- package/package.json +1 -1
package/bin/myhi.js
CHANGED
|
@@ -12,6 +12,7 @@ const __dirname = dirname(__filename);
|
|
|
12
12
|
const args = process.argv.slice(2);
|
|
13
13
|
let cmd = null;
|
|
14
14
|
let httpOnlyFlag = null; // null=不改;true=切 HTTP-only;false=切回 HTTPS
|
|
15
|
+
let hostFlag = null; // null=不改;否则持久化监听地址到 config.json(如 Tailscale IP,公网不可达)
|
|
15
16
|
for (let i = 0; i < args.length; i++) {
|
|
16
17
|
if ((args[i] === '-p' || args[i] === '--port') && args[i + 1]) {
|
|
17
18
|
process.env.PORT = args[i + 1];
|
|
@@ -19,6 +20,10 @@ for (let i = 0; i < args.length; i++) {
|
|
|
19
20
|
} else if (args[i].startsWith('--port=')) {
|
|
20
21
|
process.env.PORT = args[i].split('=')[1];
|
|
21
22
|
args.splice(i, 1); i--;
|
|
23
|
+
} else if ((args[i] === '--host' || args[i].startsWith('--host=')) && args[i].includes('=')) {
|
|
24
|
+
hostFlag = args[i].split('=')[1]; args.splice(i, 1); i--;
|
|
25
|
+
} else if (args[i] === '--host' && args[i + 1]) {
|
|
26
|
+
hostFlag = args[i + 1]; args.splice(i, 2); i--;
|
|
22
27
|
} else if (args[i] === '--http' || args[i] === '--no-https') {
|
|
23
28
|
httpOnlyFlag = true; args.splice(i, 1); i--;
|
|
24
29
|
} else if (args[i] === '--https') {
|
|
@@ -63,6 +68,24 @@ if (httpOnlyFlag !== null) {
|
|
|
63
68
|
if (!cmd) cmd = 'restart'; // 无显式命令 → 切完直接重启使其生效
|
|
64
69
|
}
|
|
65
70
|
|
|
71
|
+
// --host <addr>:持久化监听地址到 config.json(server 启动时读取,任何重启都保留)。
|
|
72
|
+
// 典型用法:`myhi --host <Tailscale IP>` 把 myhi 只绑内网,公网不可达。设完自动 restart。
|
|
73
|
+
if (hostFlag !== null) {
|
|
74
|
+
try {
|
|
75
|
+
mkdirSync(configDir, { recursive: true });
|
|
76
|
+
let cfg = {};
|
|
77
|
+
try { cfg = JSON.parse(readFileSync(configFile, 'utf8')); } catch {}
|
|
78
|
+
cfg.host = hostFlag.trim() || undefined; // 空串 = 回到默认 0.0.0.0
|
|
79
|
+
if (!cfg.host) delete cfg.host;
|
|
80
|
+
writeFileSync(configFile, JSON.stringify(cfg, null, 2));
|
|
81
|
+
console.log(`[myhi] 监听地址已设为 ${cfg.host || '0.0.0.0(全部接口)'},重启后仍保留`);
|
|
82
|
+
} catch (e) {
|
|
83
|
+
console.error('[myhi] 写入 config.json 失败:', e.message);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
if (!cmd) cmd = 'restart';
|
|
87
|
+
}
|
|
88
|
+
|
|
66
89
|
// ── 工具函数 ──────────────────────────────────────────────
|
|
67
90
|
|
|
68
91
|
function readPid() {
|