@@ -119,7 +119,7 @@ export default function CLIToolsPageClient({ machineId }) {
|
||||
if (tunnelEnabled && tunnelPublicUrl) return tunnelPublicUrl;
|
||||
if (cloudEnabled && CLOUD_URL) return CLOUD_URL;
|
||||
if (typeof window !== "undefined") return window.location.origin;
|
||||
return "http://127.0.0.1:20128";
|
||||
return "http://localhost:20128";
|
||||
};
|
||||
|
||||
if (loading) {
|
||||
|
||||
@@ -21,7 +21,7 @@ export default function DefaultToolCard({ toolId, tool, isExpanded, onToggle, ba
|
||||
: (!cloudEnabled ? "sk_9router" : "your-api-key");
|
||||
|
||||
// Add /v1 suffix only if not already present (DRY - avoid duplicate)
|
||||
const normalizedBaseUrl = baseUrl || "http://127.0.0.1:20128";
|
||||
const normalizedBaseUrl = baseUrl || "http://localhost:20128";
|
||||
const baseUrlWithV1 = normalizedBaseUrl.endsWith("/v1")
|
||||
? normalizedBaseUrl
|
||||
: `${normalizedBaseUrl}/v1`;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { useState, useEffect, useCallback } from "react";
|
||||
import { Card, Button, Badge, Input } from "@/shared/components";
|
||||
|
||||
const DEFAULT_MITM_ROUTER_BASE = "http://127.0.0.1:20128";
|
||||
const DEFAULT_MITM_ROUTER_BASE = "http://localhost:20128";
|
||||
|
||||
/**
|
||||
* Shared MITM infrastructure card — manages SSL cert + server start/stop.
|
||||
|
||||
@@ -15,7 +15,23 @@ const TUNNEL_BENEFITS = [
|
||||
const TUNNEL_PING_INTERVAL_MS = 2000;
|
||||
const TUNNEL_PING_MAX_MS = 300000;
|
||||
const STATUS_POLL_INTERVAL_MS = 5000;
|
||||
const REACHABLE_MISS_THRESHOLD = 2;
|
||||
const REACHABLE_MISS_THRESHOLD = 5;
|
||||
const CLIENT_PING_INTERVAL_MS = 10000;
|
||||
const CLIENT_PING_TIMEOUT_MS = 5000;
|
||||
|
||||
// Browser-side health probe: bypasses backend DNS issues (1.1.1.1 vs OS resolver).
|
||||
// Uses no-cors → opaque response means TLS+DNS reach succeeded, which is enough.
|
||||
async function clientPingUrl(url) {
|
||||
if (!url) return false;
|
||||
try {
|
||||
await fetch(`${url}/api/health`, {
|
||||
mode: "no-cors",
|
||||
cache: "no-store",
|
||||
signal: AbortSignal.timeout(CLIENT_PING_TIMEOUT_MS),
|
||||
});
|
||||
return true;
|
||||
} catch { return false; }
|
||||
}
|
||||
|
||||
const CAVEMAN_LEVELS = [
|
||||
{ id: "lite", label: "Lite", desc: "Drop filler, keep grammar" },
|
||||
@@ -69,6 +85,9 @@ export default function APIPageClient({ machineId }) {
|
||||
// Only flip UI to "reconnecting" after N consecutive misses to avoid spinner flicker.
|
||||
const tunnelMissRef = useRef(0);
|
||||
const tsMissRef = useRef(0);
|
||||
// Browser-side reachable cache (independent of backend DNS quirks)
|
||||
const tunnelClientReachableRef = useRef(false);
|
||||
const tsClientReachableRef = useRef(false);
|
||||
// Track whether reachable=true was ever observed in this session.
|
||||
// Distinguishes "Checking..." (initial cold cache) from "Reconnecting..." (lost connection).
|
||||
const tunnelEverReachableRef = useRef(false);
|
||||
@@ -99,10 +118,34 @@ export default function APIPageClient({ machineId }) {
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Update reachable state with miss-debounce: avoids spinner flicker when server
|
||||
// briefly returns reachable=false during background probe refresh.
|
||||
// Also flips everReachable on first success (UI uses it to distinguish Checking vs Reconnecting).
|
||||
const updateReachable = useCallback((reachable, missRef, setter, everRef, everSetter) => {
|
||||
// Browser-side periodic ping: probes tunnel/tailscale URLs directly so UI stays
|
||||
// "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);
|
||||
tunnelClientReachableRef.current = ok;
|
||||
if (ok) { tunnelMissRef.current = 0; setTunnelReachable(true); if (!tunnelEverReachableRef.current) { tunnelEverReachableRef.current = true; setTunnelEverReachable(true); } }
|
||||
} else {
|
||||
tunnelClientReachableRef.current = false;
|
||||
}
|
||||
if (tsEnabled && tsUrl) {
|
||||
const ok = await clientPingUrl(tsUrl);
|
||||
tsClientReachableRef.current = ok;
|
||||
if (ok) { tsMissRef.current = 0; setTsReachable(true); if (!tsEverReachableRef.current) { tsEverReachableRef.current = true; setTsEverReachable(true); } }
|
||||
} else {
|
||||
tsClientReachableRef.current = false;
|
||||
}
|
||||
};
|
||||
probeBoth();
|
||||
const id = setInterval(probeBoth, CLIENT_PING_INTERVAL_MS);
|
||||
return () => clearInterval(id);
|
||||
}, [tunnelEnabled, tunnelPublicUrl, 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.
|
||||
const updateReachable = useCallback((serverReachable, clientRef, missRef, setter, everRef, everSetter) => {
|
||||
const reachable = serverReachable || clientRef.current;
|
||||
if (reachable) {
|
||||
missRef.current = 0;
|
||||
setter(true);
|
||||
@@ -128,13 +171,13 @@ export default function APIPageClient({ machineId }) {
|
||||
setTunnelUrl(tUrl);
|
||||
setTunnelPublicUrl(tPublicUrl);
|
||||
setTunnelEnabled(tEnabled);
|
||||
updateReachable(!!data.tunnel?.reachable, tunnelMissRef, setTunnelReachable, tunnelEverReachableRef, setTunnelEverReachable);
|
||||
updateReachable(!!data.tunnel?.reachable, tunnelClientReachableRef, tunnelMissRef, setTunnelReachable, tunnelEverReachableRef, setTunnelEverReachable);
|
||||
|
||||
const tsEn = data.tailscale?.settingsEnabled ?? data.tailscale?.enabled ?? false;
|
||||
const tsUrlVal = data.tailscale?.tunnelUrl || "";
|
||||
setTsUrl(tsUrlVal);
|
||||
setTsEnabled(tsEn);
|
||||
updateReachable(!!data.tailscale?.reachable, tsMissRef, setTsReachable, tsEverReachableRef, setTsEverReachable);
|
||||
updateReachable(!!data.tailscale?.reachable, tsClientReachableRef, tsMissRef, setTsReachable, tsEverReachableRef, setTsEverReachable);
|
||||
} catch { /* ignore poll errors */ }
|
||||
};
|
||||
|
||||
@@ -163,13 +206,13 @@ export default function APIPageClient({ machineId }) {
|
||||
setTunnelUrl(tUrl);
|
||||
setTunnelPublicUrl(tPublicUrl);
|
||||
setTunnelEnabled(tEnabled);
|
||||
updateReachable(!!data.tunnel?.reachable, tunnelMissRef, setTunnelReachable, tunnelEverReachableRef, setTunnelEverReachable);
|
||||
updateReachable(!!data.tunnel?.reachable, tunnelClientReachableRef, tunnelMissRef, setTunnelReachable, tunnelEverReachableRef, setTunnelEverReachable);
|
||||
|
||||
const tsEn = data.tailscale?.settingsEnabled ?? data.tailscale?.enabled ?? false;
|
||||
const tsUrlVal = data.tailscale?.tunnelUrl || "";
|
||||
setTsUrl(tsUrlVal);
|
||||
setTsEnabled(tsEn);
|
||||
updateReachable(!!data.tailscale?.reachable, tsMissRef, setTsReachable, tsEverReachableRef, setTsEverReachable);
|
||||
updateReachable(!!data.tailscale?.reachable, tsClientReachableRef, tsMissRef, setTsReachable, tsEverReachableRef, setTsEverReachable);
|
||||
}
|
||||
} catch (error) {
|
||||
console.log("Error loading settings:", error);
|
||||
|
||||
@@ -235,7 +235,7 @@ export default function ComboDetailPage() {
|
||||
const examplePath = EXAMPLE_PATHS[combo.kind];
|
||||
const exampleBody = combo.kind && EXAMPLE_BODIES[combo.kind] ? EXAMPLE_BODIES[combo.kind](combo.name) : null;
|
||||
const curlExample = examplePath
|
||||
? `curl -X POST http://127.0.0.1:20128${examplePath} \\\n -H "Content-Type: application/json" \\\n -H "Authorization: Bearer ${apiKey || "YOUR_KEY"}" \\\n -d '${JSON.stringify(exampleBody)}'`
|
||||
? `curl -X POST http://localhost:20128${examplePath} \\\n -H "Content-Type: application/json" \\\n -H "Authorization: Bearer ${apiKey || "YOUR_KEY"}" \\\n -d '${JSON.stringify(exampleBody)}'`
|
||||
: "";
|
||||
const backHref = getListingHref(combo.kind);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import { getSettings, updateSettings } from "@/lib/localDb";
|
||||
|
||||
initDbHooks(getSettings, updateSettings);
|
||||
|
||||
const DEFAULT_MITM_ROUTER_BASE = "http://127.0.0.1:20128";
|
||||
const DEFAULT_MITM_ROUTER_BASE = "http://localhost:20128";
|
||||
|
||||
function normalizeMitmRouterBaseUrlInput(input) {
|
||||
if (input == null || String(input).trim() === "") {
|
||||
|
||||
15
src/app/api/version/shutdown/route.js
Normal file
15
src/app/api/version/shutdown/route.js
Normal file
@@ -0,0 +1,15 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { killAppProcesses } from "@/lib/appUpdater";
|
||||
|
||||
// Shutdown app to release file locks for manual update
|
||||
export async function POST() {
|
||||
try {
|
||||
await killAppProcesses();
|
||||
} catch { /* best effort */ }
|
||||
|
||||
const response = NextResponse.json({ success: true, message: "Shutting down for manual update..." });
|
||||
|
||||
setTimeout(() => process.exit(0), 500);
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ export default function GetStarted() {
|
||||
<div className="flex-none w-8 h-8 rounded-full bg-[#f97815]/20 text-[#f97815] flex items-center justify-center font-bold">3</div>
|
||||
<div>
|
||||
<h4 className="font-bold text-lg">Route Requests</h4>
|
||||
<p className="text-sm text-gray-500 mt-1">Point your CLI tools to http://127.0.0.1:20128</p>
|
||||
<p className="text-sm text-gray-500 mt-1">Point your CLI tools to http://localhost:20128</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -72,8 +72,8 @@ export default function GetStarted() {
|
||||
|
||||
<div className="text-gray-400 mb-6">
|
||||
<span className="text-[#f97815]">></span> Starting 9Router...<br/>
|
||||
<span className="text-[#f97815]">></span> Server running on <span className="text-blue-400">http://127.0.0.1:20128</span><br/>
|
||||
<span className="text-[#f97815]">></span> Dashboard: <span className="text-blue-400">http://127.0.0.1:20128/dashboard</span><br/>
|
||||
<span className="text-[#f97815]">></span> Server running on <span className="text-blue-400">http://localhost:20128</span><br/>
|
||||
<span className="text-[#f97815]">></span> Dashboard: <span className="text-blue-400">http://localhost:20128/dashboard</span><br/>
|
||||
<span className="text-green-400">></span> Ready to route! ✓
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user