Skip to content

Commit 9432ca3

Browse files
fix: address Copilot review on PR #4
- Require both stdin and stdout TTY for auto-open. Piped invocations like `echo | jspod` are now correctly treated as non-interactive and skip the browser open. - Extract formatUrl(host, port) helper that: - Normalizes wildcard addresses (0.0.0.0, ::, *) to localhost - Brackets IPv6 literals so `--host ::1` produces http://[::1]:5444 (was http://::1:5444, unparseable) - Use the helper in both the startup banner and the auto-open URL, so a single fix covers both surfaces. Refs #1
1 parent 149c03a commit 9432ca3

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

index.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ import { existsSync, mkdirSync, readFileSync } from 'fs';
1414
const __dirname = dirname(fileURLToPath(import.meta.url));
1515
const pkg = JSON.parse(readFileSync(join(__dirname, 'package.json'), 'utf8'));
1616

17+
// Build a browser-friendly URL from a host/port pair. Normalizes wildcard
18+
// addresses (0.0.0.0, ::) to localhost and brackets IPv6 literals so the
19+
// result is always a valid URL the user (and the browser) can open.
20+
function formatUrl(host, port) {
21+
if (host === '0.0.0.0' || host === '::' || host === '*') {
22+
return `http://localhost:${port}`;
23+
}
24+
if (host.includes(':')) {
25+
return `http://[${host}]:${port}`;
26+
}
27+
return `http://${host}:${port}`;
28+
}
29+
1730
// Parse CLI arguments
1831
const args = process.argv.slice(2);
1932
const options = {
@@ -106,7 +119,7 @@ console.log(chalk.cyan(`
106119
console.log(chalk.blue('🚀 Starting Solid server...\n'));
107120

108121
console.log(chalk.bold.white('📡 Server Configuration:\n'));
109-
console.log(chalk.cyan(' ├─ ') + chalk.white('URL: ') + chalk.bold.green(`http://${options.host === '0.0.0.0' ? 'localhost' : options.host}:${options.port}`));
122+
console.log(chalk.cyan(' ├─ ') + chalk.white('URL: ') + chalk.bold.green(formatUrl(options.host, options.port)));
110123
console.log(chalk.cyan(' ├─ ') + chalk.white('Port: ') + chalk.yellow(options.port));
111124
console.log(chalk.cyan(' ├─ ') + chalk.white('Host: ') + chalk.yellow(options.host));
112125
console.log(chalk.cyan(' ├─ ') + chalk.white('Pod Root: ') + chalk.yellow(options.root));
@@ -160,11 +173,13 @@ jss.on('error', (error) => {
160173

161174
// Auto-open the browser once the server is responsive (single-user first-run delight).
162175
// Opt out with --no-open, or by running in CI / SSH / non-TTY environments.
163-
const browserUrl = `http://${options.host === '0.0.0.0' ? 'localhost' : options.host}:${options.port}`;
176+
const browserUrl = formatUrl(options.host, options.port);
164177

165178
function shouldAutoOpen() {
166179
if (!options.open) return false;
167-
if (!process.stdout.isTTY) return false;
180+
// Require both stdin and stdout to be TTYs so that piped invocations
181+
// (e.g. `echo | jspod`) are treated as non-interactive.
182+
if (!process.stdin.isTTY || !process.stdout.isTTY) return false;
168183
if (process.env.CI) return false;
169184
if (process.env.SSH_CONNECTION || process.env.SSH_CLIENT || process.env.SSH_TTY) return false;
170185
if (process.env.TERM === 'dumb') return false;

0 commit comments

Comments
 (0)