Refactor
This commit is contained in:
24
cli/cli.js
24
cli/cli.js
@@ -61,6 +61,21 @@ const INSTALL_CMD_LATEST = `npm i -g ${APP_NAME}@latest --prefer-online`;
|
||||
|
||||
const DEFAULT_PORT = 20128;
|
||||
const DEFAULT_HOST = "0.0.0.0";
|
||||
|
||||
// First non-internal IPv4 — the address remote peers actually reach when bound to 0.0.0.0.
|
||||
function getLanIp() {
|
||||
for (const ifaces of Object.values(os.networkInterfaces())) {
|
||||
for (const i of ifaces || []) {
|
||||
if (i.family === "IPv4" && !i.internal) return i.address;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// Local URL stays "localhost"; warn separately when bound to all interfaces (network-exposed).
|
||||
function getDisplayHost() {
|
||||
return host === DEFAULT_HOST ? "localhost" : host;
|
||||
}
|
||||
const MAX_PORT_ATTEMPTS = 10;
|
||||
// Identifiers for killAllAppProcesses - only kill 9router specifically
|
||||
const PROCESS_IDENTIFIERS = [
|
||||
@@ -501,7 +516,7 @@ async function showInterfaceMenu(latestVersion) {
|
||||
|
||||
clearScreen();
|
||||
|
||||
const displayHost = host === DEFAULT_HOST ? "localhost" : host;
|
||||
const displayHost = getDisplayHost();
|
||||
|
||||
// Detect tunnel/local mode for server URL display
|
||||
let serverUrl;
|
||||
@@ -542,8 +557,13 @@ const MAX_RESTARTS = 2;
|
||||
const RESTART_RESET_MS = 30000; // Reset counter if alive > 30s
|
||||
|
||||
function startServer(latestVersion) {
|
||||
const displayHost = host === DEFAULT_HOST ? "localhost" : host;
|
||||
const displayHost = getDisplayHost();
|
||||
const url = `http://${displayHost}:${port}/dashboard`;
|
||||
// Surface real network exposure when bound to all interfaces (default 0.0.0.0).
|
||||
if (host === DEFAULT_HOST) {
|
||||
const lanIp = getLanIp();
|
||||
if (lanIp) console.log(`\x1b[33m⚠ Network-exposed: reachable at http://${lanIp}:${port} (bound 0.0.0.0). Use --host 127.0.0.1 for local-only.\x1b[0m`);
|
||||
}
|
||||
|
||||
let restartCount = 0;
|
||||
let serverStartTime = Date.now();
|
||||
|
||||
Reference in New Issue
Block a user