From 616e2ef75f2f557ac222b747702746ed0e84be31 Mon Sep 17 00:00:00 2001 From: webdevcody Date: Fri, 16 Jan 2026 22:40:36 -0500 Subject: [PATCH] feat: add HOSTNAME and VITE_HOSTNAME support for improved server URL configuration - Introduced `HOSTNAME` environment variable for user-facing URLs, defaulting to localhost. - Updated server and client code to utilize `HOSTNAME` for constructing URLs instead of hardcoded localhost. - Enhanced documentation in CLAUDE.md to reflect new configuration options. - Added `VITE_HOSTNAME` for frontend API URLs, ensuring consistent hostname usage across the application. These changes improve flexibility in server configuration and enhance the user experience by providing accurate URLs. --- CLAUDE.md | 2 ++ apps/server/src/index.ts | 10 +++++----- .../src/routes/worktree/routes/dev-server-logs.ts | 1 + apps/server/src/services/dev-server-service.ts | 7 +++++-- .../worktree-panel/hooks/use-dev-server-logs.ts | 2 +- apps/ui/src/lib/http-api-client.ts | 5 ++++- apps/ui/src/types/electron.d.ts | 1 + 7 files changed, 19 insertions(+), 9 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 48e1b9f5..d46d1284 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -167,7 +167,9 @@ Use `resolveModelString()` from `@automaker/model-resolver` to convert model ali - `ANTHROPIC_API_KEY` - Anthropic API key (or use Claude Code CLI auth) - `HOST` - Host to bind server to (default: 0.0.0.0) +- `HOSTNAME` - Hostname for user-facing URLs (default: localhost) - `PORT` - Server port (default: 3008) - `DATA_DIR` - Data storage directory (default: ./data) - `ALLOWED_ROOT_DIRECTORY` - Restrict file operations to specific directory - `AUTOMAKER_MOCK_AGENT=true` - Enable mock agent mode for CI testing +- `VITE_HOSTNAME` - Hostname for frontend API URLs (default: localhost) diff --git a/apps/server/src/index.ts b/apps/server/src/index.ts index c6e440c8..d90c7a36 100644 --- a/apps/server/src/index.ts +++ b/apps/server/src/index.ts @@ -89,6 +89,7 @@ dotenv.config(); const PORT = parseInt(process.env.PORT || '3008', 10); const HOST = process.env.HOST || '0.0.0.0'; +const HOSTNAME = process.env.HOSTNAME || 'localhost'; const DATA_DIR = process.env.DATA_DIR || './data'; const ENABLE_REQUEST_LOGGING_DEFAULT = process.env.ENABLE_REQUEST_LOGGING !== 'false'; // Default to true @@ -618,16 +619,15 @@ const startServer = (port: number, host: string) => { : 'enabled' : 'disabled'; const portStr = port.toString().padEnd(4); - const hostDisplay = host === '0.0.0.0' ? 'localhost' : host; logger.info(` ╔═══════════════════════════════════════════════════════╗ ║ Automaker Backend Server ║ ╠═══════════════════════════════════════════════════════╣ ║ Listening: ${host}:${port}${' '.repeat(Math.max(0, 34 - host.length - port.toString().length))}║ -║ HTTP API: http://${hostDisplay}:${portStr} ║ -║ WebSocket: ws://${hostDisplay}:${portStr}/api/events ║ -║ Terminal: ws://${hostDisplay}:${portStr}/api/terminal/ws ║ -║ Health: http://${hostDisplay}:${portStr}/api/health ║ +║ HTTP API: http://${HOSTNAME}:${portStr} ║ +║ WebSocket: ws://${HOSTNAME}:${portStr}/api/events ║ +║ Terminal: ws://${HOSTNAME}:${portStr}/api/terminal/ws ║ +║ Health: http://${HOSTNAME}:${portStr}/api/health ║ ║ Terminal: ${terminalStatus.padEnd(37)}║ ╚═══════════════════════════════════════════════════════╝ `); diff --git a/apps/server/src/routes/worktree/routes/dev-server-logs.ts b/apps/server/src/routes/worktree/routes/dev-server-logs.ts index 66dfed92..79d3553b 100644 --- a/apps/server/src/routes/worktree/routes/dev-server-logs.ts +++ b/apps/server/src/routes/worktree/routes/dev-server-logs.ts @@ -34,6 +34,7 @@ export function createGetDevServerLogsHandler() { result: { worktreePath: result.result.worktreePath, port: result.result.port, + url: result.result.url, logs: result.result.logs, startedAt: result.result.startedAt, }, diff --git a/apps/server/src/services/dev-server-service.ts b/apps/server/src/services/dev-server-service.ts index 5187c0c8..49f5218c 100644 --- a/apps/server/src/services/dev-server-service.ts +++ b/apps/server/src/services/dev-server-service.ts @@ -379,10 +379,11 @@ class DevServerService { // Create server info early so we can reference it in handlers // We'll add it to runningServers after verifying the process started successfully + const hostname = process.env.HOSTNAME || 'localhost'; const serverInfo: DevServerInfo = { worktreePath, port, - url: `http://localhost:${port}`, + url: `http://${hostname}:${port}`, process: devProcess, startedAt: new Date(), scrollbackBuffer: '', @@ -474,7 +475,7 @@ class DevServerService { result: { worktreePath, port, - url: `http://localhost:${port}`, + url: `http://${hostname}:${port}`, message: `Dev server started on port ${port}`, }, }; @@ -594,6 +595,7 @@ class DevServerService { result?: { worktreePath: string; port: number; + url: string; logs: string; startedAt: string; }; @@ -613,6 +615,7 @@ class DevServerService { result: { worktreePath: server.worktreePath, port: server.port, + url: server.url, logs: server.scrollbackBuffer, startedAt: server.startedAt.toISOString(), }, diff --git a/apps/ui/src/components/views/board-view/worktree-panel/hooks/use-dev-server-logs.ts b/apps/ui/src/components/views/board-view/worktree-panel/hooks/use-dev-server-logs.ts index d5472472..cdd99b07 100644 --- a/apps/ui/src/components/views/board-view/worktree-panel/hooks/use-dev-server-logs.ts +++ b/apps/ui/src/components/views/board-view/worktree-panel/hooks/use-dev-server-logs.ts @@ -93,7 +93,7 @@ export function useDevServerLogs({ worktreePath, autoSubscribe = true }: UseDevS isRunning: true, isLoading: false, port: result.result!.port, - url: `http://localhost:${result.result!.port}`, + url: result.result!.url, startedAt: result.result!.startedAt, error: null, })); diff --git a/apps/ui/src/lib/http-api-client.ts b/apps/ui/src/lib/http-api-client.ts index 3d40883e..1b13baae 100644 --- a/apps/ui/src/lib/http-api-client.ts +++ b/apps/ui/src/lib/http-api-client.ts @@ -157,7 +157,9 @@ const getServerUrl = (): string => { const envUrl = import.meta.env.VITE_SERVER_URL; if (envUrl) return envUrl; } - return 'http://localhost:3008'; + // Use VITE_HOSTNAME if set, otherwise default to localhost + const hostname = import.meta.env.VITE_HOSTNAME || 'localhost'; + return `http://${hostname}:3008`; }; /** @@ -557,6 +559,7 @@ export interface DevServerLogsResponse { result?: { worktreePath: string; port: number; + url: string; logs: string; startedAt: string; }; diff --git a/apps/ui/src/types/electron.d.ts b/apps/ui/src/types/electron.d.ts index fbba4063..054f7d4b 100644 --- a/apps/ui/src/types/electron.d.ts +++ b/apps/ui/src/types/electron.d.ts @@ -994,6 +994,7 @@ export interface WorktreeAPI { result?: { worktreePath: string; port: number; + url: string; logs: string; startedAt: string; };