Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cli/commands.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as childProcess from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { configDir } from '../config';
import { BASE_URL, isServerRunning, openBrowser, startServer, stopServer } from './http';
import { configDir, loadConfig } from '../config';
import { BASE_URL, isServerRunning, openBrowser, PORT, startServer, stopServer } from './http';

/**
* Opens (or creates) session `id`, starts the server if needed, and opens the URL in the browser.
Expand Down Expand Up @@ -33,7 +33,7 @@ export async function cmdGo(id = 'main'): Promise<void> {
sessionId = session.id;
}

const url = `${BASE_URL}/s/${sessionId}`;
const url = `http://${loadConfig().host}:${PORT}/s/${sessionId}`;
Comment thread
jesse23 marked this conversation as resolved.
Outdated
Comment thread
jesse23 marked this conversation as resolved.
Outdated
console.log(url);
openBrowser(url);
}
Expand Down
2 changes: 1 addition & 1 deletion src/cli/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const __dirname = path.dirname(__filename);
/** Active server port, resolved from `PORT` env or config default. */
export const PORT = Number(process.env.PORT) || 2346;

/** Base URL for the local server (always 127.0.0.1). */
/** Base URL for internal CLI↔server API calls (always 127.0.0.1, avoids IPv6 lookup). */
export const BASE_URL = `http://127.0.0.1:${PORT}`;

/** Returns the path to the server log file: `~/.config/webtty/server.log`. */
Expand Down
7 changes: 5 additions & 2 deletions src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ const __dirname = path.dirname(__filename);

const config = loadConfig();
const HTTP_PORT = Number(process.env.PORT) || config.port;
const HTTP_HOST = config.host;
// 'localhost' resolves to ::1 (IPv6) on modern macOS/Node; bind to 127.0.0.1 instead
// but keep 'localhost' as the display host so browser URLs use it as intended.
const HTTP_HOST_DISPLAY = config.host;
const HTTP_HOST = config.host === 'localhost' ? '127.0.0.1' : config.host;

const { distPath, wasmPath } = findGhosttyWeb();
const projectRoot = path.resolve(__dirname, '..', '..');
Expand Down Expand Up @@ -46,5 +49,5 @@ process.on('SIGINT', () => {
});

httpServer.listen(HTTP_PORT, HTTP_HOST, () => {
console.log(`listening on http://${HTTP_HOST}:${HTTP_PORT}`);
console.log(`listening on http://${HTTP_HOST_DISPLAY}:${HTTP_PORT}`);
});
Loading