mirror of
https://github.com/Kynde/airc.git
synced 2026-10-20 08:31:38 +02:00
Tailscale Funnel has been the flaky one here: the public *.ts.net path goes
dead while every local tailscale check stays green, and it takes the advertised
URL down with it. ngrok has never done that. But `publicUrl` — one string,
outranking ngrok by construction — left no way to lean on ngrok without
deleting the Funnel URL, and no place to park a third tunnel while trying it
out.
So tunnels become a group, one entry each with its own `enabled` flag:
"tunnels": {
"prefer": ["ngrok", "tailscale", "external"],
"ngrok": { "enabled": false, "domain": ..., "binary": ..., "apiUrl": ... },
"tailscale": { "enabled": false, "url": "" },
"external": { "enabled": false, "url": "" }
}
`prefer` is precedence, not exclusivity. Every enabled tunnel still reaches the
server; the first one that can name a URL is merely what gets baked into
bookmarks, the pairing QR and /api/config. Swapping the advertised route is a
reorder of that list plus a restart, with the losing tunnel left configured and
live as a spare. `external` is the slot for whatever comes next — Cloudflare, a
reverse proxy — without another schema change. A partial `prefer` ranks the
rest last rather than hiding them; an unknown name in it is a load error, since
a typo there would otherwise silently re-point the advertised URL.
Only ngrok is supervised, as before: `tailscale` and `external` are URLs airc
advertises for tunnels somebody else keeps up, which is all `publicUrl` ever
was. Because a reserved ngrok domain is knowable before the agent is up, it is
now advertised from the first request instead of after the agent reports; the
live URL replaces it when it lands (the two differ only without a reserved
domain), and both paths log through one announce().
`--no-ngrok` now means only what it says — skip the agent, let the next tunnel
down the list take over. `--no-tunnels` is new and means LAN/loopback only;
`tools/airc local` and `npm run dev` use it, which is what keeps local mode
preferring a LAN URL in pairing payloads now that disabling ngrok no longer
implies disabling everything. /healthz and /api/status gained a `tunnels` block
listing the routes in preference order with the advertised one named, and
`tools/airc status` prints that name next to the URL.
Old configs load untouched: a top-level `ngrok` block becomes `tunnels.ngrok`,
a top-level `publicUrl` becomes `tunnels.external.url`, and a file still in
that shape keeps its old precedence — publicUrl over ngrok — so pulling this
cannot silently re-point an existing pairing at a different tunnel. Only a
config that opts into `tunnels` gets the new ngrok-first default.
test/tunnels.test.js covers the ordering, both migration paths and the two
flags. Checked live against both orderings on a scratch port before restarting
the real server; with ngrok advertised, both it and the still-enabled Funnel
answer 200. Worth naming the cost: ngrok's free-tier interstitial does not
render in the Tesla browser, so the car keeps its ts.net bookmark, which works
precisely because a demoted tunnel stays up.
68 lines
2.3 KiB
Plaintext
68 lines
2.3 KiB
Plaintext
#compdef airc
|
|
# zsh completion for airc (tools/airc). Versioned in the repo; put it on $fpath
|
|
# by symlinking it into a completion dir (mirrors how ~/bin/airc -> tools/airc):
|
|
# ln -s ~/airc/completions/_airc ~/.zsh/completion/_airc
|
|
# After editing, restart zsh (or rerun compinit) to pick up changes.
|
|
|
|
# Live tmux session names for --session / --tmux-target.
|
|
_airc_sessions() {
|
|
local -a sessions
|
|
sessions=( ${(f)"$(tmux list-sessions -F '#{session_name}' 2>/dev/null)"} )
|
|
(( ${#sessions} )) && _describe -t sessions 'tmux session' sessions
|
|
}
|
|
|
|
# Options the server accepts (on/local/restart pass these through to
|
|
# src/server.js; the parser lives in src/config.js parseArgs).
|
|
_airc_server_args() {
|
|
_arguments \
|
|
'*--host[bind address]:host:_hosts' \
|
|
'*--port[listen port]:port:' \
|
|
'*--session[tmux session]:session:_airc_sessions' \
|
|
'*--tmux-target[tmux target (alias of --session)]:target:_airc_sessions' \
|
|
'--config[path to config.json]:config file:_files' \
|
|
'--no-ngrok[do not start ngrok; other tunnels stay advertised]' \
|
|
'--no-tunnels[advertise no tunnel at all; LAN/loopback only]' \
|
|
'--no-tls[disable HTTPS; serve HTTP only]' \
|
|
'--print-url[print the URL and exit]' \
|
|
'--pair[print pairing info]' \
|
|
'(-h --help)'{-h,--help}'[show help]'
|
|
}
|
|
|
|
_airc() {
|
|
local curcontext=$curcontext state line
|
|
typeset -A opt_args
|
|
|
|
local -a subcommands=(
|
|
'on:start the tmux remote server using config defaults'
|
|
'local:start for same-WLAN phone access (--host 0.0.0.0 --no-tunnels)'
|
|
'off:stop the background server'
|
|
'restart:stop then start'
|
|
'status:show process and /healthz state'
|
|
'url:print configured view URL'
|
|
'pair-app:print Android app pairing QR/JSON with control token'
|
|
'pair-web:print browser QR/URL/token with view token'
|
|
'pair-web-control:print browser QR/URL/token with control token'
|
|
'logs:print the background server log path'
|
|
)
|
|
|
|
_arguments -C \
|
|
'1:command:->command' \
|
|
'*::arg:->args'
|
|
|
|
case $state in
|
|
command) _describe -t commands 'airc command' subcommands ;;
|
|
args)
|
|
case ${line[1]} in
|
|
on|local|restart) _airc_server_args ;;
|
|
status) _arguments '--json[machine-readable output]' ;;
|
|
esac
|
|
;;
|
|
esac
|
|
}
|
|
|
|
if [[ $funcstack[1] = _airc ]]; then
|
|
_airc "$@"
|
|
else
|
|
compdef _airc airc
|
|
fi
|