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:
parent
104628ed9c
commit
f04c1a5dc3
@ -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 });
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user