@newbeebox/newbeebox-app-engine-cli 1.7.0 → 1.7.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/package.json +1 -1
- package/src/forward.js +16 -2
package/package.json
CHANGED
package/src/forward.js
CHANGED
|
@@ -12,7 +12,7 @@ import { readFileSync, writeFileSync } from 'node:fs'
|
|
|
12
12
|
import WebSocket from 'ws'
|
|
13
13
|
import { apiBase } from './config.js'
|
|
14
14
|
import { CLI_VERSION } from './version.js'
|
|
15
|
-
import { request } from './http.js'
|
|
15
|
+
import { request, ApiError } from './http.js'
|
|
16
16
|
import * as out from './output.js'
|
|
17
17
|
|
|
18
18
|
const isWin = platform() === 'win32'
|
|
@@ -22,11 +22,25 @@ async function ensureLoggedIn(cfg) {
|
|
|
22
22
|
await request(cfg, 'GET', '/me')
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
// ensureAppReachable app 转发启动前的一次预检:GET /apps/:id 同时走 AuthRequired(验登录)
|
|
26
|
+
// 与 AppOwnership(验存在+归属)。应用不存在/不归本人 → 抛错,绝不开监听。
|
|
27
|
+
// 一次调用顶「验活 + 验目标」两件事——避免凭空对垃圾 appid 起一个永远连不通的本地监听。
|
|
28
|
+
async function ensureAppReachable(cfg, appid) {
|
|
29
|
+
try {
|
|
30
|
+
await request(cfg, 'GET', `/apps/${encodeURIComponent(appid)}`)
|
|
31
|
+
} catch (e) {
|
|
32
|
+
// 应用不存在/无权访问:给清晰提示,不外泄后端内部错误串。
|
|
33
|
+
// 鉴权(AuthError)/网络(NetworkError)错误原样上抛,交 run() 分类(提示 nae login / 网络)。
|
|
34
|
+
if (e instanceof ApiError) throw new Error(`应用 ${appid} 不存在或无权访问(用 nae apps 查看你的应用)`)
|
|
35
|
+
throw e
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
25
39
|
// --- app 端口转发 ---
|
|
26
40
|
|
|
27
41
|
// forwardApp 在本地起 TCP server,把每条连接桥到平台隧道。前台常驻,Ctrl-C 退出。
|
|
28
42
|
export async function forwardApp(cfg, appid, opts) {
|
|
29
|
-
await
|
|
43
|
+
await ensureAppReachable(cfg, appid)
|
|
30
44
|
const remotePort = opts.port // undefined → 平台取应用容器端口
|
|
31
45
|
const path = `/apps/${appid}/forward` + (remotePort ? `?port=${remotePort}` : '')
|
|
32
46
|
let active = 0
|