fix(terminal): proxy WebSocket through host in daemonless mode

When DENCHCLAW_DAEMONLESS=1, route the terminal WebSocket through
the app host instead of connecting directly to 127.0.0.1, allowing
it to work in environments without direct port access.
This commit is contained in:
kumarabhirup 2026-03-18 16:56:01 -07:00
parent 104628ed9c
commit f04c1a5dc3
No known key found for this signature in database
GPG Key ID: DB7CA2289CAB0167
2 changed files with 10 additions and 3 deletions

View File

@ -5,5 +5,6 @@ export const dynamic = "force-dynamic";
export function GET() {
const port = getTerminalPort();
return NextResponse.json({ port });
const proxy = process.env.DENCHCLAW_DAEMONLESS === "1";
return NextResponse.json({ port, proxy });
}

View File

@ -167,16 +167,22 @@ function TerminalViewport({
const cols = terminal.cols > 0 ? terminal.cols : 80;
const rows = terminal.rows > 0 ? terminal.rows : 24;
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
let useProxy = false;
let wsPort = DEFAULT_WS_PORT;
try {
const res = await fetch("/api/terminal/port");
const json = await res.json();
if (json.port) wsPort = json.port;
if (json.proxy) useProxy = true;
} catch {}
if (disposed) return;
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
const wsUrl = `${protocol}//127.0.0.1:${wsPort}`;
const wsUrl = useProxy
? `${protocol}//${window.location.host}/terminal-ws/`
: `${protocol}//127.0.0.1:${wsPort}`;
const ws = new WebSocket(wsUrl);
wsRef.current = ws;