fix: bind to 127.0.0.1 when config.host is 'localhost'#27
Merged
Conversation
On modern macOS/Node, 'localhost' resolves to ::1 (IPv6), causing the server to fail or be unreachable when browsers block 127.0.0.1 URLs. Internal CLI API calls always use 127.0.0.1; the browser URL uses the configured host as-is so 'localhost' is preserved in opened URLs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adjusts how webtty binds and advertises its loopback host to avoid IPv6-only binds when users configure host: "localhost" (notably on macOS/Node 17+), while keeping the user-facing URL as localhost.
Changes:
- Bind the HTTP server to
127.0.0.1whenconfig.host === "localhost"but loglocalhostas the display host. - Clarify CLI internal API base URL documentation (always
127.0.0.1). - Build the browser-opened URL in
cmdGofromloadConfig().hostrather thanBASE_URL.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/server/index.ts | Separates bind host vs display host; binds to IPv4 when config host is localhost. |
| src/cli/http.ts | Updates comment clarifying why CLI uses 127.0.0.1 for internal calls. |
| src/cli/commands.ts | Uses config host for the browser URL in cmdGo and imports PORT for URL construction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Extract toBrowserHost() to map bind-all addresses to 'localhost' and bracket bare IPv6 addresses, so the browser URL is always valid and routable regardless of config.host value. Add unit tests for all cases. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
'localhost'resolves to::1(IPv6 loopback), causinghttpServer.listento bind on IPv6 only — making the server unreachable for browsers that block127.0.0.1URLs but expectlocalhost127.0.0.1whenconfig.host === 'localhost'while keepinglocalhostin the displayed and browser-opened URLBASE_URL) always use127.0.0.1; browser URL is built fromloadConfig().hostat call time incmdGoTest plan
"host": "localhost"in~/.config/webtty/config.jsonwebtty— server should start and printlistening on http://localhost:<port>http://localhost:<port>/s/main(not127.0.0.1)webtty stopand other API commands still work (they use127.0.0.1internally)🤖 Generated with Claude Code