Skip to content

Add --host flag to control server bind address (#1)#3

Merged
Postmodum37 merged 2 commits intoPostmodum37:mainfrom
abien:main
Mar 8, 2026
Merged

Add --host flag to control server bind address (#1)#3
Postmodum37 merged 2 commits intoPostmodum37:mainfrom
abien:main

Conversation

@abien
Copy link
Copy Markdown
Contributor

@abien abien commented Mar 4, 2026

Problem

When running ocwatch via bunx on WSL2 (Linux), the server binds to IPv6 by default, making it inaccessible from the Windows host browser.
Bun.serve() without an explicit hostname parameter binds to IPv6 on Linux (TCP *:50234 on IPv6), even though the Bun docs (https://bun.sh/docs/api/http) state the default is "0.0.0.0".
There is no way to fix this externally. Unlike port (which supports $BUN_PORT / $PORT env vars), Bun has no environment variable, no bunfig.toml setting, and no CLI flag to control the bind address — the hostname property must be set in code via Bun.serve() options.

Fix

This patch adds a --host

flag (defaulting to localhost) that passes the hostname property to Bun.serve(), giving users explicit control over the bind address. CORS is also adjusted accordingly — --host 0.0.0.0 sets origin: "*" since requests will come from external addresses.
Usage: bunx ocwatch --host 0.0.0.0
This is relevant for anyone running ocwatch in WSL2, containers, or remote/headless environments where the default binding is not reachable.

* Initial plan

* Add --host flag to bind server to custom address (e.g. 0.0.0.0)

Co-authored-by: abien <[email protected]>

---------

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: abien <[email protected]>
Copy link
Copy Markdown
Owner

@Postmodum37 Postmodum37 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR — solves a real pain point for WSL2/container users and the implementation is clean. Two issues below.

…value

Address PR review feedback:
- CORS and displayHost now treat :: (IPv6) as wildcard alongside 0.0.0.0
- --host with no value warns instead of silently falling back to localhost
@Postmodum37 Postmodum37 merged commit 91aa8ef into Postmodum37:main Mar 8, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants