pi-hub-server 0.10.0 → 0.10.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/CHANGELOG.md +12 -0
- package/README.md +20 -0
- package/bin/pi-hub.mjs +6 -0
- package/package.json +1 -1
- package/src/cli-control.mjs +2 -0
- package/src/server.mjs +9 -0
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,18 @@
|
|
|
5
5
|
> `package.json` 的 `version` 是唯一真源:`src/update-check.mjs` 的 `HUB_VERSION`、`-h` banner、
|
|
6
6
|
> `/v1/health` 与 `/v1/update` 的 `server.current` 全部读它。发版顺序:**先改 version,再打同名 tag**。
|
|
7
7
|
|
|
8
|
+
## v0.10.1 — 2026-12-06
|
|
9
|
+
|
|
10
|
+
**`/v1/health` 报真实监听地址 + `pi-hub status` 用它纠偏**
|
|
11
|
+
- `/v1/health` 新增 `listen: {host, port}`(取 `server.address()`,即真的在监听的那个地址)。
|
|
12
|
+
- 真机踩到:systemd unit 里 `Environment=PI_HUB_HOST=127.0.0.1` 覆盖了 `listen.json` 的 `0.0.0.0`,
|
|
13
|
+
`pi-hub status` 照配置打 `http://0.0.0.0:6768(手机填 192.168…)`——**根本没人监听这个地址**,
|
|
14
|
+
新手照着填必然连不上。现在 `status` 优先读 `health.listen`,实测同一条命令变成
|
|
15
|
+
`http://127.0.0.1:6768(只在回环:手机要连见 pi-hub tutorial)`。
|
|
16
|
+
- `test/cli-serve.mjs` 加确定性用例:假 health 回 `listen:{host:"127.0.0.2",port:4242}`,
|
|
17
|
+
`status --host 0.0.0.0` 必须打前者、不许打后者(阴性对照:改回旧逻辑必红);`test/smoke.mjs` 断言
|
|
18
|
+
`health.listen` 与真实绑定一致。
|
|
19
|
+
|
|
8
20
|
## v0.10.0 — 2026-12-06
|
|
9
21
|
|
|
10
22
|
**新手友好的首次部署(lane onboarding-r13)**
|
package/README.md
CHANGED
|
@@ -262,6 +262,26 @@ node bin/pi-hub.mjs serve
|
|
|
262
262
|
> 网页与 API 同源、走同一套鉴权(Bearer / 设备签名 / cookie)。`http://` 下 cookie 没有 `Secure` 也是同网段可嗅探的,
|
|
263
263
|
> 出门请走 Tailscale/WireGuard(见「限制」)。
|
|
264
264
|
|
|
265
|
+
## `/v1/reach`(客户端/网页向导读它)
|
|
266
|
+
|
|
267
|
+
`GET /v1/reach`(需鉴权!不裸奔内网 IP)返回「这台 hub 现在能从哪些地址连上」:
|
|
268
|
+
|
|
269
|
+
```json
|
|
270
|
+
{ "listeningAll": true, "listeningLoopbackOnly": false, "port": 6768, "host": "0.0.0.0", "firstRun": true,
|
|
271
|
+
"candidates": [
|
|
272
|
+
{ "mode": "loopback", "url": "http://127.0.0.1:6768", "usable": true, "hint": "…" },
|
|
273
|
+
{ "mode": "usb", "url": "http://127.0.0.1:6768", "usable": false, "hint": "… adb -s <serial> reverse tcp:6768 tcp:6768" },
|
|
274
|
+
{ "mode": "lan", "url": "http://192.168.42.97:6768", "usable": true, "hint": "…" },
|
|
275
|
+
{ "mode": "tailscale", "url": "http://100.126.217.90:6768","usable": true, "hint": "…" },
|
|
276
|
+
{ "mode": "funnel", "url": "https://<机器名>.<tailnet>.ts.net", "usable": false, "hint": "tailscale funnel --bg http://127.0.0.1:6768" }
|
|
277
|
+
] }
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
- 地址是**实测**的:枚举本机网卡并跳过 `docker0`/`veth`/`br-*` 这类对端连不上的虚拟网桥
|
|
281
|
+
(`src/reach.mjs`),Tailscale 段按 `100.64.0.0/10` 单独识别;`usable:false` 的条目带「先做这一步」的具体命令。
|
|
282
|
+
- `firstRun` = 还没配对过任何设备;网页端据此决定是否弹首次运行向导。
|
|
283
|
+
- 顺序固定为从易到难:`loopback → lan → tailscale → funnel`(`usb` 永远在 `loopback` 之后、`usable:false`)。
|
|
284
|
+
|
|
265
285
|
## 更新检查
|
|
266
286
|
|
|
267
287
|
`GET /v1/update` 是客户端的**唯一更新源**(手机不直连 GitHub;hub 不可达时客户端只显示「无法检查」):
|
package/bin/pi-hub.mjs
CHANGED
|
@@ -235,6 +235,12 @@ function printStatus({ port, host, snap }) {
|
|
|
235
235
|
const svc = snap.svc;
|
|
236
236
|
const health = snap.health;
|
|
237
237
|
const running = health.up;
|
|
238
|
+
// 服务真的绑在哪个地址上以 /v1/health.listen 为准:systemd 的 PI_HUB_HOST 会覆盖
|
|
239
|
+
// listen.json,以前 status 打的是「配置里写的」,可能根本没人在监听(新手照着填就错)。
|
|
240
|
+
if (running && health.listen && typeof health.listen.host === "string") {
|
|
241
|
+
host = health.listen.host;
|
|
242
|
+
port = Number(health.listen.port) || port;
|
|
243
|
+
}
|
|
238
244
|
const svcText = svc.usable
|
|
239
245
|
? `systemd ${svc.unit}.service ${svc.active}/${svc.sub}${svc.mainPid ? `,pid ${svc.mainPid}` : ""}`
|
|
240
246
|
: `${svc.reason ?? "无 systemd 单元"}${snap.pidfile?.pid ? `;pidfile pid ${snap.pidfile.pid}${snap.pidAlive ? "(进程在)" : "(进程已退,残留)"}` : ""}`;
|
package/package.json
CHANGED
package/src/cli-control.mjs
CHANGED
|
@@ -138,6 +138,8 @@ export async function probeHealth({ port, host = "127.0.0.1", token = null, time
|
|
|
138
138
|
sessionLock: body.sessionLock ?? null,
|
|
139
139
|
sessionLockInfo: body.sessionLockInfo ?? null,
|
|
140
140
|
piVersion: body.piVersion ?? null,
|
|
141
|
+
// 真实绑定地址(`pi-hub status` 用它纠正 listen.json 与实际监听不一致的情形)
|
|
142
|
+
listen: body.listen && typeof body.listen === "object" ? body.listen : null,
|
|
141
143
|
};
|
|
142
144
|
}
|
|
143
145
|
if (res.status === 401) return { up: true, ok: false, unauthorized: true, status: 401, ms: Date.now() - started };
|
package/src/server.mjs
CHANGED
|
@@ -1210,6 +1210,15 @@ export function createHubServer({ fetchJson } = {}) {
|
|
|
1210
1210
|
// pi 实测版本(后台探测);未探到时为 null。
|
|
1211
1211
|
piVersion: piVersion.version,
|
|
1212
1212
|
piVersionCheckedAt: piVersion.checkedAt,
|
|
1213
|
+
// 真实绑定值(`server.address()`):CLI `status` 以前显示 listen.json 里的值,
|
|
1214
|
+
// 被 systemd 的 PI_HUB_HOST 覆盖时就报了一个没人监听的地址(新手会照着填)。
|
|
1215
|
+
listen: (() => {
|
|
1216
|
+
const bound = server.address() ?? {};
|
|
1217
|
+
return {
|
|
1218
|
+
host: typeof bound.address === "string" ? bound.address : HOST,
|
|
1219
|
+
port: typeof bound.port === "number" ? bound.port : PORT,
|
|
1220
|
+
};
|
|
1221
|
+
})(),
|
|
1213
1222
|
});
|
|
1214
1223
|
}
|
|
1215
1224
|
|