diff --git a/scripts/dev-web-hmr.mjs b/scripts/dev-web-hmr.mjs index 95e8332c..47cb8855 100644 --- a/scripts/dev-web-hmr.mjs +++ b/scripts/dev-web-hmr.mjs @@ -1,6 +1,7 @@ #!/usr/bin/env node import { spawn } from 'node:child_process'; import { existsSync, rmSync } from 'node:fs'; +import os from 'node:os'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; @@ -82,6 +83,20 @@ async function stopChildTree(child) { const uiPort = process.env.OPENCHAMBER_HMR_UI_PORT || '5180'; const backendPort = process.env.OPENCHAMBER_HMR_API_PORT || '3902'; +const hmrHost = process.env.OPENCHAMBER_HMR_HOST || '127.0.0.1'; + +function getLanAddresses() { + const addresses = []; + + for (const networkAddresses of Object.values(os.networkInterfaces())) { + for (const address of networkAddresses || []) { + if (address.family !== 'IPv4' || address.internal) continue; + addresses.push(address.address); + } + } + + return addresses; +} function clearViteCache() { const cacheDirs = [ @@ -103,7 +118,7 @@ const api = run('api', 'bun', ['run', '--cwd', 'packages/web', 'dev:server:watch const vite = run( 'vite', 'bun', - ['x', 'vite', '--force', '--host', '127.0.0.1', '--port', uiPort, '--strictPort'], + ['x', 'vite', '--force', '--host', hmrHost, '--port', uiPort, '--strictPort'], { OPENCHAMBER_PORT: backendPort, OPENCHAMBER_DISABLE_PWA_DEV: '1', @@ -112,6 +127,16 @@ const vite = run( ); console.log(`[dev:web:hmr] UI with HMR: http://127.0.0.1:${uiPort}`); +if (hmrHost === '0.0.0.0' || hmrHost === '::') { + const lanAddresses = getLanAddresses(); + if (lanAddresses.length > 0) { + for (const address of lanAddresses) { + console.log(`[dev:web:hmr] LAN/mobile UI: http://${address}:${uiPort}`); + } + } else { + console.log('[dev:web:hmr] LAN/mobile UI: no LAN IPv4 address found'); + } +} console.log(`[dev:web:hmr] API: http://127.0.0.1:${backendPort}`); console.log('[dev:web:hmr] IMPORTANT: open UI URL above for HMR; backend URL has no HMR');