diff --git a/static/start-interactive.js b/static/start-interactive.js index 60d10e6..b9ac4b0 100644 --- a/static/start-interactive.js +++ b/static/start-interactive.js @@ -10,6 +10,7 @@ document.addEventListener("DOMContentLoaded", function () { if (!interactiveMode && event.key === "Enter") { const command = input.value.trim(); if (command === "start-interactive") { + startInteractiveSession(); input.value = ""; event.preventDefault(); @@ -19,6 +20,30 @@ document.addEventListener("DOMContentLoaded", function () { } }); + // Helper: get ?ip=…&port=… from the current location +function getQueryParam(name) { + return new URLSearchParams(window.location.search).get(name); +} + +function makeWsUrl() { + const proxyIp = getQueryParam("ip"); // "10.0.0.42" if you came via /proxyAgent + const proxyPort = getQueryParam("port"); // "8080" + const usingProxy = proxyIp && proxyPort; // truthy only in that case + + if (usingProxy) { + // Build ws(s):///proxyAgent/terminal?ip=…&port=… + const u = new URL("/proxyAgent/terminal", window.location); + u.searchParams.set("ip", proxyIp); + u.searchParams.set("port", proxyPort); + u.protocol = u.protocol === "https:" ? "wss:" : "ws:"; + return u.toString(); + } + // Fallback: open directly on the agent we’re already on + const u = new URL("/terminal", window.location); + u.protocol = u.protocol === "https:" ? "wss:" : "ws:"; + return u.toString(); +} + function startInteractiveSession() { interactiveMode = true; // Hide the normal terminal and input. @@ -55,7 +80,8 @@ document.addEventListener("DOMContentLoaded", function () { console.log("Initial fit: container width =", xtermContainer.offsetWidth, "cols =", term.cols); }, 100); - interactiveWS = new WebSocket("ws://" + location.host + "/terminal"); + interactiveWS = new WebSocket(makeWsUrl()); + // interactiveWS = new WebSocket("ws://" + location.host + "/terminal"); interactiveWS.binaryType = "arraybuffer"; interactiveWS.onopen = function () { diff --git a/static/xterm-addon-fit.js b/static/xterm/xterm-addon-fit.js similarity index 100% rename from static/xterm-addon-fit.js rename to static/xterm/xterm-addon-fit.js diff --git a/static/xterm.css b/static/xterm/xterm.css similarity index 100% rename from static/xterm.css rename to static/xterm/xterm.css diff --git a/static/xterm.js b/static/xterm/xterm.js similarity index 100% rename from static/xterm.js rename to static/xterm/xterm.js diff --git a/templates/index.html b/templates/index.html index 7796d4c..8a70ba8 100644 --- a/templates/index.html +++ b/templates/index.html @@ -11,9 +11,9 @@ - - - + + +