Skip to content

Commit 6094222

Browse files
Merge pull request #22 from riclib/configurable-bind-host
Allow binding the HTTP server to a non-loopback address
2 parents 003afe1 + cf0613f commit 6094222

2 files changed

Lines changed: 15 additions & 3 deletions

File tree

packages/runtime/src/server/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
type FocusUpdate,
3131
SERVER_PORT,
3232
SERVER_HOST,
33+
LOCAL_CLIENT_HOST,
3334
PID_FILE,
3435
SERVER_IDLE_TIMEOUT_MS,
3536
STUCK_RUNNING_TIMEOUT_MS,
@@ -2125,7 +2126,10 @@ export function startServer(mux: MuxProvider, extraProviders?: MuxProvider[], wa
21252126

21262127
// --- Bootstrap ---
21272128

2128-
for (const p of allProviders) p.setupHooks(SERVER_HOST, SERVER_PORT);
2129+
// Local tmux hooks always curl loopback, regardless of what address
2130+
// the server binds to. SERVER_HOST may be 0.0.0.0 or a bridge IP to
2131+
// accept remote POSTs, but in-process hooks should never use that.
2132+
for (const p of allProviders) p.setupHooks(LOCAL_CLIENT_HOST, SERVER_PORT);
21292133
const sidebarPresence = reconcileSidebarPresence();
21302134
if (sidebarPresence.visible) {
21312135
for (const { provider } of listSidebarPanesByProvider()) {

packages/runtime/src/shared.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,16 @@ import type { AgentStatus, AgentEvent } from "./contracts/agent";
22
import type { MuxSessionInfo } from "./contracts/mux";
33
import type { SessionFilterMode } from "./config";
44

5-
export const SERVER_PORT = 7391;
6-
export const SERVER_HOST = "127.0.0.1";
5+
export const SERVER_PORT = Number(process.env.OPENSESSIONS_PORT ?? 7391);
6+
// Bind address for the HTTP server. Override with OPENSESSIONS_HOST to
7+
// accept POSTs from other hosts (e.g. "0.0.0.0" to listen on all
8+
// interfaces, or a specific bridge IP such as "10.4.250.1"). Defaults
9+
// to loopback so out-of-the-box installs stay local-only.
10+
export const SERVER_HOST = process.env.OPENSESSIONS_HOST ?? "127.0.0.1";
11+
// Address that local in-process hooks use to reach the server. Always
12+
// loopback — remote callers should build their own URL pointing at
13+
// whichever address SERVER_HOST is bound to.
14+
export const LOCAL_CLIENT_HOST = "127.0.0.1";
715
export const PID_FILE = "/tmp/opensessions.pid";
816
export const SERVER_IDLE_TIMEOUT_MS = 30_000;
917
export const STUCK_RUNNING_TIMEOUT_MS = 3 * 60 * 1000;

0 commit comments

Comments
 (0)