claudroid-bridge 0.1.0 → 0.1.1
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/README.md +19 -5
- package/dist/cli.js +10 -5
- package/dist/cloudflared.js +177 -0
- package/dist/tunnel.js +47 -9
- package/dist/version.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,15 +15,15 @@ Cloudflare Tunnel。
|
|
|
15
15
|
- 主机上已能运行 Claude Code:执行过 `claude login`,或环境里配置了
|
|
16
16
|
`ANTHROPIC_API_KEY` 等。默认使用 Agent SDK 自带的 CLI;也可用
|
|
17
17
|
`claudeExecutable` / `--config` 指向系统安装的 `claude`。
|
|
18
|
-
-
|
|
18
|
+
- 使用隧道时无需预先安装 `cloudflared`:首次启用会自动下载官方版本并校验 sha256(见下文)。
|
|
19
19
|
|
|
20
20
|
## 安装
|
|
21
21
|
|
|
22
22
|
```bash
|
|
23
|
-
# 从 npm
|
|
23
|
+
# 从 npm
|
|
24
24
|
npm install -g claudroid-bridge
|
|
25
25
|
|
|
26
|
-
#
|
|
26
|
+
# 从源码(开发/未发布版本)
|
|
27
27
|
git clone <repo> && cd claudroid/bridge
|
|
28
28
|
npm ci
|
|
29
29
|
npm run build
|
|
@@ -87,7 +87,7 @@ claudroid-bridge devices revoke <id> # 吊销设备令牌
|
|
|
87
87
|
| `claudeExecutable` | 可选;不填时使用 Agent SDK 随包的 CLI |
|
|
88
88
|
| `tunnel.mode` | `off` / `quick` / `named` |
|
|
89
89
|
| `tunnel.token` / `hostname` | named 隧道必填 |
|
|
90
|
-
| `tunnel.cloudflaredPath` |
|
|
90
|
+
| `tunnel.cloudflaredPath` | 可选;指定自定义 cloudflared。留空时先复用 `PATH`,缺失则自动下载到 `~/.config/claudroid-bridge/bin/` |
|
|
91
91
|
|
|
92
92
|
`start` 的等价参数:`--bind`、`--port`、`--root`(可重复)、`--tunnel`、
|
|
93
93
|
`--tunnel-token`、`--tunnel-hostname`、`--allow-bypass`、`--config`。
|
|
@@ -104,6 +104,12 @@ claudroid-bridge start --tunnel named \
|
|
|
104
104
|
--tunnel-hostname claude.example.com
|
|
105
105
|
```
|
|
106
106
|
|
|
107
|
+
**cloudflared 无需手动安装。** 首次启用隧道时,daemon 会从 Cloudflare 官方 GitHub
|
|
108
|
+
Release 下载固定版本的连接器,按内置 SHA-256 校验后安装到
|
|
109
|
+
`~/.config/claudroid-bridge/bin/cloudflared`(Windows 为 `cloudflared.exe`),之后复用。
|
|
110
|
+
若 `PATH` 里已有 cloudflared,会优先使用;`tunnel.cloudflaredPath` 可强制指定。
|
|
111
|
+
下载失败或校验不符时隧道进入错误状态并在 App 中显示原因,不会带病启动。
|
|
112
|
+
|
|
107
113
|
daemon 负责启动与监督 `cloudflared`,异常退出按指数退避重启;隧道状态与公网地址通过
|
|
108
114
|
`/v1/tunnel` 和 SSE 推给 App,也可以在手机的主机详情页开关。quick 地址会变化,长期使用
|
|
109
115
|
请配置 named tunnel。
|
|
@@ -161,8 +167,16 @@ src/turns.ts turn 生命周期与有界事件缓冲
|
|
|
161
167
|
src/sdk-runner.ts Agent SDK query() 封装(stream-json 透传、resume、abort)
|
|
162
168
|
src/permissions.ts canUseTool → SSE → 等待手机决定
|
|
163
169
|
src/files.ts roots 校验与文件 RPC
|
|
164
|
-
src/tunnel.ts cloudflared
|
|
170
|
+
src/tunnel.ts cloudflared 启动、URL 解析与监督
|
|
171
|
+
src/cloudflared.ts 固定版本下载、sha256 校验与托管路径
|
|
165
172
|
src/config.ts 配置文件读写与归一化
|
|
166
173
|
src/events.ts SSE 事件总线
|
|
167
174
|
test/ vitest;用假 runner 覆盖协议、权限、重连与路径逃逸
|
|
168
175
|
```
|
|
176
|
+
|
|
177
|
+
## 发布新版本
|
|
178
|
+
|
|
179
|
+
1. `npm version 0.1.1 --no-git-tag-version`,并同步 `src/version.ts` 的 `DAEMON_VERSION`。
|
|
180
|
+
2. `npm test && npm run build`。
|
|
181
|
+
3. `npx npm@11 stage publish --access public`(当前 granular token 为 stage-only)。
|
|
182
|
+
4. 在 npmjs.com 的 **Account settings → Staged Packages** 用 2FA 批准。
|
package/dist/cli.js
CHANGED
|
@@ -4,6 +4,7 @@ import { existsSync, readFileSync } from "node:fs";
|
|
|
4
4
|
import { networkInterfaces } from "node:os";
|
|
5
5
|
import { dirname, join, resolve } from "node:path";
|
|
6
6
|
import { AuthService, DeviceStore } from "./auth.js";
|
|
7
|
+
import { managedCloudflaredPath } from "./cloudflared.js";
|
|
7
8
|
import { configPath, defaultConfig, loadConfig, pairingPath, publicConfig, saveConfig, writeFilePrivate, } from "./config.js";
|
|
8
9
|
import { EventBus } from "./events.js";
|
|
9
10
|
import { FileService } from "./files.js";
|
|
@@ -222,7 +223,7 @@ async function start(options) {
|
|
|
222
223
|
console.log(`隧道已就绪: ${status.url}`);
|
|
223
224
|
if (status.state === "error" && status.error)
|
|
224
225
|
console.error(`隧道错误: ${status.error}`);
|
|
225
|
-
});
|
|
226
|
+
}, undefined, undefined, (message) => console.log(message));
|
|
226
227
|
server = createBridgeServer({
|
|
227
228
|
config,
|
|
228
229
|
auth,
|
|
@@ -278,15 +279,17 @@ function printDoctor(options) {
|
|
|
278
279
|
console.log(`✓ 工作区: ${root}`);
|
|
279
280
|
}
|
|
280
281
|
}
|
|
281
|
-
const
|
|
282
|
+
const managed = managedCloudflaredPath();
|
|
283
|
+
const candidate = config.tunnel.cloudflaredPath ?? (existsSync(managed) ? managed : "cloudflared");
|
|
284
|
+
const cloudflared = spawnSync(candidate, ["--version"], {
|
|
282
285
|
encoding: "utf8",
|
|
283
286
|
});
|
|
284
287
|
if (cloudflared.error || cloudflared.status !== 0) {
|
|
285
|
-
console.log("! 未找到 cloudflared
|
|
286
|
-
console.log("
|
|
288
|
+
console.log("! 未找到 cloudflared;启用隧道时会自动下载官方版本并校验 sha256");
|
|
289
|
+
console.log(" 也可以手动安装,或用 tunnel.cloudflaredPath 指定可执行文件");
|
|
287
290
|
}
|
|
288
291
|
else {
|
|
289
|
-
console.log(`✓ cloudflared: ${(cloudflared.stdout || "").trim()}`);
|
|
292
|
+
console.log(`✓ cloudflared: ${(cloudflared.stdout || "").trim()}${candidate === managed ? "(托管)" : ""}`);
|
|
290
293
|
}
|
|
291
294
|
if (config.tunnel.mode === "named" && (!config.tunnel.token || !config.tunnel.hostname)) {
|
|
292
295
|
console.error("✗ named 隧道需要 tunnel.token 与 tunnel.hostname");
|
|
@@ -352,6 +355,8 @@ start 选项:
|
|
|
352
355
|
--tunnel-hostname <host> named 隧道的公网域名
|
|
353
356
|
--allow-bypass 允许 App 请求 bypassPermissions(默认关闭)
|
|
354
357
|
|
|
358
|
+
隧道首次启用时会自动下载并校验 cloudflared;tunnel.cloudflaredPath 可覆盖。
|
|
359
|
+
|
|
355
360
|
配置文件示例见 bridge/README.md。`);
|
|
356
361
|
}
|
|
357
362
|
async function main() {
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { spawnSync } from "node:child_process";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
3
|
+
import { createReadStream, createWriteStream, chmodSync, mkdirSync, renameSync, rmSync, statSync } from "node:fs";
|
|
4
|
+
import { get as httpsGet } from "node:https";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { bridgeHome } from "./config.js";
|
|
7
|
+
/**
|
|
8
|
+
* Pin the connector release and its published SHA-256 digests. The binary is
|
|
9
|
+
* downloaded on first use so `npm i -g claudroid-bridge` + `start --tunnel`
|
|
10
|
+
* works without a manual cloudflared install, while still verifying integrity.
|
|
11
|
+
*/
|
|
12
|
+
export const CLOUDFLARED_VERSION = "2026.11.1";
|
|
13
|
+
const ASSETS = {
|
|
14
|
+
"linux-x64": {
|
|
15
|
+
file: "cloudflared-linux-amd64",
|
|
16
|
+
sha256: "97bb3b02d23a5980fc9c15a1a270e692da1923f103f920d5b16d4931d5ab55e7",
|
|
17
|
+
archive: "binary",
|
|
18
|
+
},
|
|
19
|
+
"linux-arm64": {
|
|
20
|
+
file: "cloudflared-linux-arm64",
|
|
21
|
+
sha256: "b155cec3e48e489cfb8e5c602769fb8c771083018d8881d68b4d18a791567c5a",
|
|
22
|
+
archive: "binary",
|
|
23
|
+
},
|
|
24
|
+
"darwin-x64": {
|
|
25
|
+
file: "cloudflared-darwin-amd64.tgz",
|
|
26
|
+
sha256: "5e0403b188dfee71fbd9b995e7dc9910d61b661c52371935ab6475d41185632f",
|
|
27
|
+
archive: "tgz",
|
|
28
|
+
},
|
|
29
|
+
"darwin-arm64": {
|
|
30
|
+
file: "cloudflared-darwin-arm64.tgz",
|
|
31
|
+
sha256: "02fe4bcf08f2c09699cff30658228a739a0c47fb75f3653d1b8772a27ade4462",
|
|
32
|
+
archive: "tgz",
|
|
33
|
+
},
|
|
34
|
+
"win32-x64": {
|
|
35
|
+
file: "cloudflared-windows-amd64.exe",
|
|
36
|
+
sha256: "341deda3db5ec498a0482254d6c38c0b7cf01a30c37bb5dd95d2216d08955e35",
|
|
37
|
+
archive: "binary",
|
|
38
|
+
},
|
|
39
|
+
};
|
|
40
|
+
export function assetFor(platform, arch) {
|
|
41
|
+
return ASSETS[`${platform}-${arch}`] ?? null;
|
|
42
|
+
}
|
|
43
|
+
export function managedCloudflaredPath(home = bridgeHome(), platform = process.platform) {
|
|
44
|
+
return join(home, "bin", platform === "win32" ? "cloudflared.exe" : "cloudflared");
|
|
45
|
+
}
|
|
46
|
+
function releaseUrl(asset) {
|
|
47
|
+
return `https://github.com/cloudflare/cloudflared/releases/download/${CLOUDFLARED_VERSION}/${asset.file}`;
|
|
48
|
+
}
|
|
49
|
+
export function sha256File(path) {
|
|
50
|
+
return new Promise((resolve, reject) => {
|
|
51
|
+
const hash = createHash("sha256");
|
|
52
|
+
const stream = createReadStream(path);
|
|
53
|
+
stream.on("data", (chunk) => hash.update(chunk));
|
|
54
|
+
stream.on("error", reject);
|
|
55
|
+
stream.on("end", () => resolve(hash.digest("hex")));
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function isExecutable(path, platform) {
|
|
59
|
+
try {
|
|
60
|
+
const stat = statSync(path);
|
|
61
|
+
if (!stat.isFile())
|
|
62
|
+
return false;
|
|
63
|
+
return platform === "win32" || (stat.mode & 0o111) !== 0;
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
function onPath() {
|
|
70
|
+
const result = spawnSync("cloudflared", ["--version"], { stdio: "ignore" });
|
|
71
|
+
return !result.error && result.status === 0;
|
|
72
|
+
}
|
|
73
|
+
function hasCurl() {
|
|
74
|
+
const result = spawnSync("curl", ["--version"], { stdio: "ignore" });
|
|
75
|
+
return !result.error && result.status === 0;
|
|
76
|
+
}
|
|
77
|
+
function curlDownload(url, dest) {
|
|
78
|
+
const result = spawnSync("curl", ["-fL", "--retry", "3", "--connect-timeout", "20", "--max-time", "600", "-o", dest, url], { encoding: "utf8", timeout: 620_000 });
|
|
79
|
+
if (result.error)
|
|
80
|
+
throw new Error(`下载 cloudflared 失败:${result.error.message}`);
|
|
81
|
+
if (result.status !== 0) {
|
|
82
|
+
const detail = (result.stderr || "").trim();
|
|
83
|
+
throw new Error(`下载 cloudflared 失败(curl exit ${String(result.status)})${detail ? `:${detail}` : ""}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function httpsDownload(url, dest, redirects = 5) {
|
|
87
|
+
return new Promise((resolve, reject) => {
|
|
88
|
+
const request = httpsGet(url, { headers: { "user-agent": `claudroid-bridge/${CLOUDFLARED_VERSION}` }, timeout: 30_000 }, (response) => {
|
|
89
|
+
const status = response.statusCode ?? 0;
|
|
90
|
+
if (status >= 300 && status < 400 && response.headers.location && redirects > 0) {
|
|
91
|
+
response.resume();
|
|
92
|
+
resolve(httpsDownload(new URL(response.headers.location, url).toString(), dest, redirects - 1));
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (status !== 200) {
|
|
96
|
+
response.resume();
|
|
97
|
+
reject(new Error(`下载 cloudflared 失败:HTTP ${String(status)}`));
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
const file = createWriteStream(dest, { mode: 0o600 });
|
|
101
|
+
response.pipe(file);
|
|
102
|
+
response.on("error", reject);
|
|
103
|
+
file.on("error", reject);
|
|
104
|
+
file.on("finish", () => file.close(() => resolve()));
|
|
105
|
+
});
|
|
106
|
+
request.on("timeout", () => request.destroy(new Error("下载 cloudflared 超时")));
|
|
107
|
+
request.on("error", reject);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function download(url, dest) {
|
|
111
|
+
if (hasCurl()) {
|
|
112
|
+
curlDownload(url, dest);
|
|
113
|
+
return Promise.resolve();
|
|
114
|
+
}
|
|
115
|
+
return httpsDownload(url, dest);
|
|
116
|
+
}
|
|
117
|
+
function extractTgz(archive, dest) {
|
|
118
|
+
const result = spawnSync("tar", ["-xzf", archive, "-C", dest, "cloudflared"], {
|
|
119
|
+
encoding: "utf8",
|
|
120
|
+
timeout: 120_000,
|
|
121
|
+
});
|
|
122
|
+
if (result.error)
|
|
123
|
+
throw new Error(`解压 cloudflared 失败:${result.error.message}`);
|
|
124
|
+
if (result.status !== 0) {
|
|
125
|
+
throw new Error(`解压 cloudflared 失败(tar exit ${String(result.status)})`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Return a usable cloudflared path, downloading the pinned official release on
|
|
130
|
+
* first use. `tunnel.cloudflaredPath` always wins; an existing PATH install is
|
|
131
|
+
* reused before anything is downloaded.
|
|
132
|
+
*/
|
|
133
|
+
export async function ensureCloudflared(config, log = () => undefined, platform = process.platform, arch = process.arch) {
|
|
134
|
+
if (config.cloudflaredPath)
|
|
135
|
+
return config.cloudflaredPath;
|
|
136
|
+
const managed = managedCloudflaredPath(bridgeHome(), platform);
|
|
137
|
+
if (isExecutable(managed, platform))
|
|
138
|
+
return managed;
|
|
139
|
+
if (onPath())
|
|
140
|
+
return "cloudflared";
|
|
141
|
+
const asset = assetFor(platform, arch);
|
|
142
|
+
if (!asset) {
|
|
143
|
+
throw new Error(`当前平台 ${platform}/${arch} 没有可自动安装的 cloudflared,请手动安装后设置 tunnel.cloudflaredPath。`);
|
|
144
|
+
}
|
|
145
|
+
const binDir = join(bridgeHome(), "bin");
|
|
146
|
+
mkdirSync(binDir, { recursive: true, mode: 0o700 });
|
|
147
|
+
const temp = join(binDir, `.cloudflared-${String(process.pid)}.download`);
|
|
148
|
+
log(`未找到 cloudflared,正在从官方 Release 下载 ${CLOUDFLARED_VERSION}…`);
|
|
149
|
+
try {
|
|
150
|
+
await download(releaseUrl(asset), temp);
|
|
151
|
+
const actual = await sha256File(temp);
|
|
152
|
+
if (actual !== asset.sha256) {
|
|
153
|
+
throw new Error(`cloudflared 校验失败(期望 ${asset.sha256},实际 ${actual}),已丢弃下载文件。`);
|
|
154
|
+
}
|
|
155
|
+
if (asset.archive === "tgz") {
|
|
156
|
+
const extractDir = join(binDir, `.cloudflared-${String(process.pid)}.extract`);
|
|
157
|
+
mkdirSync(extractDir, { recursive: true, mode: 0o700 });
|
|
158
|
+
try {
|
|
159
|
+
extractTgz(temp, extractDir);
|
|
160
|
+
renameSync(join(extractDir, "cloudflared"), managed);
|
|
161
|
+
}
|
|
162
|
+
finally {
|
|
163
|
+
rmSync(extractDir, { recursive: true, force: true });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else {
|
|
167
|
+
renameSync(temp, managed);
|
|
168
|
+
}
|
|
169
|
+
if (platform !== "win32")
|
|
170
|
+
chmodSync(managed, 0o755);
|
|
171
|
+
log(`cloudflared ${CLOUDFLARED_VERSION} 已安装到 ${managed}`);
|
|
172
|
+
return managed;
|
|
173
|
+
}
|
|
174
|
+
finally {
|
|
175
|
+
rmSync(temp, { force: true });
|
|
176
|
+
}
|
|
177
|
+
}
|
package/dist/tunnel.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { spawn } from "node:child_process";
|
|
2
|
+
import { ensureCloudflared } from "./cloudflared.js";
|
|
2
3
|
function quickTunnelUrl(line) {
|
|
3
4
|
return line.match(/https:\/\/[a-z0-9-]+\.trycloudflare\.com/i)?.[0];
|
|
4
5
|
}
|
|
5
6
|
/**
|
|
6
7
|
* Supervises a cloudflared process. The connector must run on the host because it
|
|
7
8
|
* is what exposes the host's loopback bridge; the phone only stores the public URL.
|
|
9
|
+
* The binary is resolved (and, when missing, downloaded from the pinned official
|
|
10
|
+
* release) on demand, so enabling a tunnel needs no manual cloudflared install.
|
|
8
11
|
*/
|
|
9
12
|
export class TunnelManager {
|
|
10
13
|
config;
|
|
@@ -13,14 +16,19 @@ export class TunnelManager {
|
|
|
13
16
|
status;
|
|
14
17
|
child = null;
|
|
15
18
|
stopped = true;
|
|
19
|
+
launching = false;
|
|
20
|
+
generation = 0;
|
|
21
|
+
resolvedBinary = null;
|
|
16
22
|
attempt = 0;
|
|
17
23
|
restartTimer = null;
|
|
18
24
|
spawnFn;
|
|
19
|
-
|
|
25
|
+
ensureBinary;
|
|
26
|
+
constructor(config, port, onChange, spawnFn = spawn, ensureBinary, log = () => undefined) {
|
|
20
27
|
this.config = config;
|
|
21
28
|
this.port = port;
|
|
22
29
|
this.onChange = onChange;
|
|
23
30
|
this.spawnFn = spawnFn;
|
|
31
|
+
this.ensureBinary = ensureBinary ?? (() => ensureCloudflared(this.config, log));
|
|
24
32
|
this.status = { mode: config.mode, state: "off", changedAt: Date.now() };
|
|
25
33
|
}
|
|
26
34
|
current() {
|
|
@@ -38,13 +46,15 @@ export class TunnelManager {
|
|
|
38
46
|
});
|
|
39
47
|
return;
|
|
40
48
|
}
|
|
41
|
-
if (this.child)
|
|
49
|
+
if (this.child || this.launching)
|
|
42
50
|
return;
|
|
43
51
|
this.stopped = false;
|
|
44
52
|
this.launch();
|
|
45
53
|
}
|
|
46
54
|
stop() {
|
|
47
55
|
this.stopped = true;
|
|
56
|
+
this.generation += 1;
|
|
57
|
+
this.launching = false;
|
|
48
58
|
if (this.restartTimer) {
|
|
49
59
|
clearTimeout(this.restartTimer);
|
|
50
60
|
this.restartTimer = null;
|
|
@@ -67,10 +77,8 @@ export class TunnelManager {
|
|
|
67
77
|
launch() {
|
|
68
78
|
if (this.stopped)
|
|
69
79
|
return;
|
|
70
|
-
const
|
|
71
|
-
|
|
72
|
-
? ["tunnel", "--no-autoupdate", "--url", `http://127.0.0.1:${this.port}`]
|
|
73
|
-
: ["tunnel", "--no-autoupdate", "run", "--token", this.config.token ?? ""];
|
|
80
|
+
const generation = ++this.generation;
|
|
81
|
+
this.launching = true;
|
|
74
82
|
this.set({
|
|
75
83
|
state: "starting",
|
|
76
84
|
url: this.config.mode === "named" && this.config.hostname
|
|
@@ -78,6 +86,35 @@ export class TunnelManager {
|
|
|
78
86
|
: undefined,
|
|
79
87
|
error: undefined,
|
|
80
88
|
});
|
|
89
|
+
void this.resolveBinary()
|
|
90
|
+
.then((binary) => {
|
|
91
|
+
if (this.stopped || generation !== this.generation)
|
|
92
|
+
return;
|
|
93
|
+
this.launching = false;
|
|
94
|
+
this.spawnChild(binary);
|
|
95
|
+
})
|
|
96
|
+
.catch((error) => {
|
|
97
|
+
if (this.stopped || generation !== this.generation)
|
|
98
|
+
return;
|
|
99
|
+
this.launching = false;
|
|
100
|
+
// A failed download/installation is permanent until the user retries;
|
|
101
|
+
// do not hammer the network with the crash-restart backoff.
|
|
102
|
+
this.fail(error instanceof Error ? error.message : String(error), false);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
async resolveBinary() {
|
|
106
|
+
if (this.resolvedBinary)
|
|
107
|
+
return this.resolvedBinary;
|
|
108
|
+
const binary = this.config.cloudflaredPath || (await this.ensureBinary());
|
|
109
|
+
this.resolvedBinary = binary;
|
|
110
|
+
return binary;
|
|
111
|
+
}
|
|
112
|
+
spawnChild(binary) {
|
|
113
|
+
if (this.stopped)
|
|
114
|
+
return;
|
|
115
|
+
const args = this.config.mode === "quick"
|
|
116
|
+
? ["tunnel", "--no-autoupdate", "--url", `http://127.0.0.1:${this.port}`]
|
|
117
|
+
: ["tunnel", "--no-autoupdate", "run", "--token", this.config.token ?? ""];
|
|
81
118
|
let child;
|
|
82
119
|
try {
|
|
83
120
|
child = this.spawnFn(binary, args, { stdio: ["ignore", "pipe", "pipe"] });
|
|
@@ -97,7 +134,7 @@ export class TunnelManager {
|
|
|
97
134
|
child.on("error", (error) => {
|
|
98
135
|
this.child = null;
|
|
99
136
|
const message = error && typeof error === "object" && "code" in error && error.code === "ENOENT"
|
|
100
|
-
? "未找到 cloudflared
|
|
137
|
+
? "未找到 cloudflared。请检查 tunnel.cloudflaredPath,或删除该配置让守护进程自动下载。"
|
|
101
138
|
: error instanceof Error
|
|
102
139
|
? error.message
|
|
103
140
|
: String(error);
|
|
@@ -126,9 +163,10 @@ export class TunnelManager {
|
|
|
126
163
|
});
|
|
127
164
|
}
|
|
128
165
|
}
|
|
129
|
-
fail(message) {
|
|
166
|
+
fail(message, retry = true) {
|
|
130
167
|
this.set({ state: "error", error: message });
|
|
131
|
-
|
|
168
|
+
if (retry)
|
|
169
|
+
this.scheduleRestart();
|
|
132
170
|
}
|
|
133
171
|
scheduleRestart() {
|
|
134
172
|
if (this.stopped || this.restartTimer)
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const DAEMON_VERSION = "0.1.
|
|
1
|
+
export const DAEMON_VERSION = "0.1.1";
|