@hamsterbase/evidra 0.11.0 → 0.11.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
CHANGED
|
@@ -19,6 +19,13 @@ const routerPort = 24751;
|
|
|
19
19
|
const validDomain = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z0-9-]{2,63}$/;
|
|
20
20
|
const uuid = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/i;
|
|
21
21
|
const variable = (key) => 'EVIDRA_SHARE_' + key;
|
|
22
|
+
const tunnelEnv = {
|
|
23
|
+
PATH: process.env.PATH,
|
|
24
|
+
HOME: os.homedir(),
|
|
25
|
+
...Object.fromEntries(
|
|
26
|
+
Object.entries(process.env).filter(([key]) => /^(http|https|all|no)_proxy$/i.test(key)),
|
|
27
|
+
),
|
|
28
|
+
};
|
|
22
29
|
|
|
23
30
|
function configuration() {
|
|
24
31
|
const defaults = fs.existsSync(configFile) ? parseEnv(fs.readFileSync(configFile, 'utf8')) : {};
|
|
@@ -191,7 +198,7 @@ async function serve() {
|
|
|
191
198
|
fs.rmSync(pidFile, { force: true });
|
|
192
199
|
connectorToken = config.TUNNEL_TOKEN;
|
|
193
200
|
const child = spawn(process.execPath, [fileURLToPath(import.meta.url), 'connector'], {
|
|
194
|
-
env: {
|
|
201
|
+
env: { ...tunnelEnv, TUNNEL_TOKEN: connectorToken },
|
|
195
202
|
stdio: ['pipe', 'ignore', 'ignore', 'ipc'],
|
|
196
203
|
});
|
|
197
204
|
child.once('message', (pid) => {
|
|
@@ -442,7 +449,12 @@ async function main() {
|
|
|
442
449
|
const child = spawn(process.execPath, [fileURLToPath(import.meta.url), 'serve'], {
|
|
443
450
|
detached: true,
|
|
444
451
|
stdio: ['ignore', 'ignore', log],
|
|
445
|
-
env: {
|
|
452
|
+
env: {
|
|
453
|
+
...tunnelEnv,
|
|
454
|
+
NODE_USE_ENV_PROXY: process.env.NODE_USE_ENV_PROXY ?? '1',
|
|
455
|
+
// 指标探测与转发到本机报告的请求始终走回环地址。
|
|
456
|
+
no_proxy: [tunnelEnv.no_proxy || tunnelEnv.NO_PROXY, '127.0.0.1'].filter(Boolean).join(','),
|
|
457
|
+
},
|
|
446
458
|
});
|
|
447
459
|
child.unref();
|
|
448
460
|
fs.closeSync(log);
|
|
@@ -148,15 +148,22 @@ LOCAL=http://127.0.0.1:$PORT
|
|
|
148
148
|
json() {
|
|
149
149
|
node -e 'let s="";process.stdin.on("data",d=>s+=d).on("end",()=>{try{process.stdout.write(String(JSON.parse(s)[process.argv[1]]??""))}catch{}})' "$1"
|
|
150
150
|
}
|
|
151
|
-
is_401() { [[ $(curl
|
|
151
|
+
is_401() { [[ $(curl -s -o /dev/null -w '%{http_code}' --max-time 5 "$@") == 401 ]]; }
|
|
152
152
|
|
|
153
153
|
# 窗口存在且其中进程未退出
|
|
154
154
|
alive() { [[ $(tmux display-message -p -t "=$S:=$1" '#{pane_dead}' 2>/dev/null) == 0 ]]; }
|
|
155
155
|
# 在会话 S 的窗口 $1 中运行命令:缺窗口就新建,已有窗口则替换其中的进程。
|
|
156
156
|
# 进程退出后窗口保留(remain-on-exit)便于查看报错,下次运行时重新启动。
|
|
157
157
|
run_in() {
|
|
158
|
-
local win=$1
|
|
158
|
+
local win=$1 key
|
|
159
|
+
local -a pane_env=(-e "PATH=$PATH")
|
|
159
160
|
shift
|
|
161
|
+
if [[ $win == tunnel ]]; then
|
|
162
|
+
# tmux 服务可能早已启动,把当前 shell 的代理设置传给新隧道。
|
|
163
|
+
for key in HTTP_PROXY http_proxy HTTPS_PROXY https_proxy ALL_PROXY all_proxy NO_PROXY no_proxy; do
|
|
164
|
+
if [[ -n ${!key+x} ]]; then pane_env+=(-e "$key=${!key}"); fi
|
|
165
|
+
done
|
|
166
|
+
fi
|
|
160
167
|
if ! tmux has-session -t "=$S" 2>/dev/null; then
|
|
161
168
|
tmux new-session -d -s "$S" -n "$win"
|
|
162
169
|
elif ! tmux list-panes -t "=$S:=$win" >/dev/null 2>&1; then
|
|
@@ -165,7 +172,7 @@ run_in() {
|
|
|
165
172
|
tmux set-option -w -t "=$S:=$win" remain-on-exit on
|
|
166
173
|
# 多个参数时 tmux 直接执行,不经过用户 shell(zsh 会把 =会话:=窗口 当作命令路径展开)。
|
|
167
174
|
# 传入当前 PATH:tmux 服务可能早已在别的环境中启动,找不到 nvm 的 node 或刚装的 cloudflared。
|
|
168
|
-
tmux respawn-pane -k
|
|
175
|
+
tmux respawn-pane -k "${pane_env[@]}" -t "=$S:=$win" "$@"
|
|
169
176
|
}
|
|
170
177
|
# 失败时打印窗口最后的输出并退出
|
|
171
178
|
fail_in() {
|
|
@@ -183,7 +190,7 @@ login_repo_root() {
|
|
|
183
190
|
start_report() {
|
|
184
191
|
run_in report "${BIN[@]}" start --repo "$ROOT" --port "$PORT" --password "$PASSWORD"
|
|
185
192
|
local deadline=$((SECONDS + 60))
|
|
186
|
-
until is_401 "$LOCAL/api/project"; do
|
|
193
|
+
until is_401 --noproxy '*' "$LOCAL/api/project"; do
|
|
187
194
|
alive report && ((SECONDS < deadline)) || fail_in report "Evidra 未能在 60 秒内启动"
|
|
188
195
|
sleep 0.5
|
|
189
196
|
done
|
|
@@ -324,9 +331,7 @@ HOST=$(quick_host)
|
|
|
324
331
|
if alive tunnel && [[ -n $HOST ]]; then
|
|
325
332
|
TAG=复用
|
|
326
333
|
else
|
|
327
|
-
|
|
328
|
-
run_in tunnel env -u HTTP_PROXY -u http_proxy -u HTTPS_PROXY -u https_proxy -u ALL_PROXY -u all_proxy \
|
|
329
|
-
cloudflared tunnel --no-autoupdate --url "$LOCAL" --metrics "127.0.0.1:$MPORT"
|
|
334
|
+
run_in tunnel cloudflared tunnel --no-autoupdate --url "$LOCAL" --metrics "127.0.0.1:$MPORT"
|
|
330
335
|
HOST= deadline=$((SECONDS + 90))
|
|
331
336
|
until [[ -n $HOST ]] && quick_ready; do
|
|
332
337
|
alive tunnel && ((SECONDS < deadline)) || fail_in tunnel "公网隧道未能在 90 秒内就绪"
|