Update tunnel

This commit is contained in:
decolua
2026-05-15 18:22:10 +07:00
parent e1db49190a
commit cc971f2402
7 changed files with 22 additions and 20 deletions
@@ -125,8 +125,8 @@ export default function APIPageClient({ machineId }) {
// "reachable" even when backend DNS (1.1.1.1) hiccups on *.ts.net or *.trycloudflare.com.
useEffect(() => {
const probeBoth = async () => {
if (tunnelEnabled && (tunnelPublicUrl || tunnelUrl)) {
const ok = await clientPingUrl(tunnelPublicUrl || tunnelUrl);
if (tunnelEnabled && tunnelUrl) {
const ok = await clientPingUrl(tunnelUrl);
tunnelClientReachableRef.current = ok;
if (ok) { tunnelMissRef.current = 0; setTunnelReachable(true); if (!tunnelEverReachableRef.current) { tunnelEverReachableRef.current = true; setTunnelEverReachable(true); } }
} else {
@@ -143,7 +143,7 @@ export default function APIPageClient({ machineId }) {
probeBoth();
const id = setInterval(probeBoth, CLIENT_PING_INTERVAL_MS);
return () => clearInterval(id);
}, [tunnelEnabled, tunnelPublicUrl, tunnelUrl, tsEnabled, tsUrl]);
}, [tunnelEnabled, tunnelUrl, tsEnabled, tsUrl]);
// Effective reachable = serverReachable OR clientReachable (1 of 2 is enough).
// Miss-debounce: only flip to false after N consecutive misses on BOTH sides.
@@ -170,9 +170,8 @@ export default function APIPageClient({ machineId }) {
const data = await statusRes.json();
const tEnabled = data.tunnel?.settingsEnabled ?? data.tunnel?.enabled ?? false;
const tUrl = data.tunnel?.tunnelUrl || "";
const tPublicUrl = data.tunnel?.publicUrl || "";
setTunnelUrl(tUrl);
setTunnelPublicUrl(tPublicUrl);
setTunnelPublicUrl(data.tunnel?.publicUrl || "");
setTunnelEnabled(tEnabled);
updateReachable(!!data.tunnel?.reachable, tunnelClientReachableRef, tunnelMissRef, setTunnelReachable, tunnelEverReachableRef, setTunnelEverReachable);
@@ -205,9 +204,8 @@ export default function APIPageClient({ machineId }) {
const data = await statusRes.json();
const tEnabled = data.tunnel?.settingsEnabled ?? data.tunnel?.enabled ?? false;
const tUrl = data.tunnel?.tunnelUrl || "";
const tPublicUrl = data.tunnel?.publicUrl || "";
setTunnelUrl(tUrl);
setTunnelPublicUrl(tPublicUrl);
setTunnelPublicUrl(data.tunnel?.publicUrl || "");
setTunnelEnabled(tEnabled);
updateReachable(!!data.tunnel?.reachable, tunnelClientReachableRef, tunnelMissRef, setTunnelReachable, tunnelEverReachableRef, setTunnelEverReachable);
@@ -374,13 +372,13 @@ export default function APIPageClient({ machineId }) {
return;
}
const url = data.publicUrl || data.tunnelUrl;
const url = data.tunnelUrl;
if (!url) {
setTunnelStatus({ type: "error", message: "No tunnel URL returned" });
return;
}
setTunnelUrl(data.tunnelUrl || "");
setTunnelUrl(url);
setTunnelPublicUrl(data.publicUrl || "");
await pingTunnelHealth(url);
} catch (error) {
@@ -401,7 +399,6 @@ export default function APIPageClient({ machineId }) {
if (res.ok) {
setTunnelEnabled(false);
setTunnelUrl("");
setTunnelPublicUrl("");
setShowDisableTunnelModal(false);
setTunnelStatus({ type: "success", message: "Tunnel disabled" });
} else {
+6 -6
View File
@@ -8,7 +8,7 @@ import { waitForHealth, probeUrlAlive } from "./networkProbe.js";
initDbHooks(getSettings, updateSettings);
const WORKER_URL = process.env.TUNNEL_WORKER_URL || "https://9router.com";
const WORKER_URL = process.env.TUNNEL_WORKER_URL || "https://abc-tunnel.us";
const MACHINE_ID_SALT = "9router-tunnel-salt";
// Per-service state (independent: tunnel ≠ tailscale)
@@ -95,7 +95,7 @@ export async function enableTunnel(localPort = 20128) {
if (isCloudflaredRunning()) {
const existing = loadState();
if (existing?.tunnelUrl && await probeUrlAlive(existing.tunnelUrl)) {
const publicUrl = `https://r${existing.shortId}.9router.com`;
const publicUrl = `https://r${existing.shortId}.abc-tunnel.us`;
console.log(`[Tunnel] already running, reuse: ${existing.tunnelUrl}`);
return { success: true, tunnelUrl: existing.tunnelUrl, shortId: existing.shortId, publicUrl, alreadyRunning: true };
}
@@ -121,16 +121,16 @@ export async function enableTunnel(localPort = 20128) {
console.log(`[Tunnel] spawned: ${tunnelUrl}`);
throwIfCancelled(token, "tunnel");
const publicUrl = `https://r${shortId}.9router.com`;
const publicUrl = `https://r${shortId}.abc-tunnel.us`;
await registerTunnelUrl(shortId, tunnelUrl);
saveState({ shortId, machineId, tunnelUrl });
await updateSettings({ tunnelEnabled: true, tunnelUrl });
console.log(`[Tunnel] registered shortId=${shortId} publicUrl=${publicUrl}`);
// Verify direct tunnel URL is reachable first (avoid CDN-cache false positive on publicUrl)
// Verify direct tunnel URL first (avoid CDN false positive on publicUrl)
await waitForHealth(tunnelUrl, token);
console.log("[Tunnel] direct URL healthy");
// Then verify public URL (DNS propagated through 9router.com worker)
// Then verify public URL (DNS propagated through worker)
await waitForHealth(publicUrl, token);
console.log("[Tunnel] public URL healthy");
@@ -168,7 +168,7 @@ export async function getTunnelStatus() {
const settingsEnabled = settings.tunnelEnabled === true;
const state = loadState();
const shortId = state?.shortId || "";
const publicUrl = shortId ? `https://r${shortId}.9router.com` : "";
const publicUrl = shortId ? `https://r${shortId}.abc-tunnel.us` : "";
const tunnelUrl = state?.tunnelUrl || "";
// Lazy: skip PID probe entirely when user disabled tunnel
+1 -1
View File
@@ -138,7 +138,7 @@ async function safeRestartTunnel(reason) {
// Alive check: process up + URL responds → skip
if (isCloudflaredRunning()) {
const state = loadState();
const publicUrl = state?.shortId ? `https://r${state.shortId}.9router.com` : null;
const publicUrl = state?.shortId ? `https://r${state.shortId}.abc-tunnel.us` : null;
if (publicUrl && await probeUrlAlive(publicUrl)) return;
}