Skip to content

feat: support binding dev server to all network interfaces via --host#12

Open
hackxixi wants to merge 2 commits into
PeakCode-AI:mainfrom
hackxixi:feat/host-binding
Open

feat: support binding dev server to all network interfaces via --host#12
hackxixi wants to merge 2 commits into
PeakCode-AI:mainfrom
hackxixi:feat/host-binding

Conversation

@hackxixi

Copy link
Copy Markdown

Summary

  • Adds --host support to bun run dev so the dev server can bind to any network interface (e.g. bun run dev -- --host 0.0.0.0), enabling LAN access from phones/tablets/remote machines.
  • Fixes a lurking bug in wsTransport.ts where the WS fallback URL used window.location.port (the Vite web port, 5733) instead of the actual WS server port (3773), breaking external connections.
  • Also conditionalises hmr.host so hot-module reloading works for remote devices (previously pinned to localhost, causing HMR to fail on LAN clients).
  • Includes fixes for four pre-existing TypeScript errors that were hidden by Turbo's early-exit behaviour; they would block bun typecheck once the first failure was resolved.

Changes

Host binding (5 files):

  • turbo.json — add PEAKCODE_HOST and VITE_WS_PORT to globalEnv so child processes receive them
  • scripts/dev-runner.ts — compute isWildcardHost; for wildcard binds inject VITE_WS_PORT and clear VITE_WS_URL (browser constructs the URL from window.location.hostname + port); for explicit hosts set VITE_WS_URL directly
  • apps/web/vite.config.ts — bind server.host to PEAKCODE_HOST; define VITE_WS_PORT; conditionalise hmr.host (omit for wildcard so remote HMR works, pin to localhost for local/Electron)
  • apps/web/src/wsTransport.ts — fix fallback URL to use VITE_WS_PORT instead of window.location.port
  • apps/web/src/vite-env.d.ts — declare VITE_WS_URL and VITE_WS_PORT in ImportMetaEnv

Pre-existing typecheck fixes (4 files):

  • apps/server/src/anthropicAdapter.ts — narrow error-body via Record<string, unknown> before accessing .error (didn't exist on OpenAIChatResponse)
  • apps/server/src/gateway.ts — add explicit return-type annotation on flatMap callback (union inferred too narrowly)
  • apps/server/src/http.ts — cast entry as string | undefined after Array.isArray guard (ReadonlyArray is not narrowed out)
  • apps/web/src/routes/_chat.settings.tsx — pass disabled={props.disabled ?? false} to avoid exactOptionalPropertyTypes mismatch

Test plan

  • bun fmt && bun lint && bun typecheck — all pass (verified locally)
  • bun.lock — zero changes (verified: git diff --stat bun.lock is empty)
  • Local access unchanged: bun run dev (no flags) still serves on localhost:5733
  • LAN access: bun run dev -- --host 0.0.0.0, open http://<LAN_IP>:5733 from another device — app loads and WS connects (ws://<LAN_IP>:3773/ws status 101)
  • Remote HMR: edit a source file while a remote device has the app open — hot update appears without page reload

https://claude.ai/code/session_01B95xcqmnLyWiAhApQdjtLC

hackxixi added 2 commits June 19, 2026 12:44
- Pass PEAKCODE_HOST and VITE_WS_PORT through turbo globalEnv so child
  processes (Vite, server) receive the host configuration
- Read PEAKCODE_HOST in vite.config.ts to bind Vite's dev server to the
  configured interface instead of always defaulting to localhost
- Inject VITE_WS_PORT when binding to a wildcard address (0.0.0.0 / ::)
  so the browser can construct the correct WS URL from
  window.location.hostname + the server port, rather than a hardcoded
  loopback address
- Fix wsTransport.ts fallback URL: was using window.location.port (Vite
  port 5733) instead of the WS server port (3773), breaking external
  connections
- Add VITE_WS_URL and VITE_WS_PORT to ImportMetaEnv type declarations
- Conditionalise hmr.host: pin to localhost for local/Electron paths
  (BrowserWindow reliability), omit when binding to a wildcard address
  so remote devices can reach HMR via their own window.location.hostname

Usage: bun run dev -- --host 0.0.0.0

Claude-Session: https://claude.ai/code/session_01B95xcqmnLyWiAhApQdjtLC
These errors were introduced by prior commits (gateway / model-channel
changes) and caused bun typecheck to fail on main before this PR.
Turbo's early-exit behaviour hid most of them behind the first failure.
Fixing them here so the codebase passes full typecheck as required by
AGENTS.md.

- anthropicAdapter.ts: narrow error-body via Record<string, unknown>
  cast before accessing .error (Property does not exist on
  OpenAIChatResponse)
- gateway.ts: add explicit return-type annotation on the flatMap
  callback in responsesContentToChatContent (TypeScript inferred the
  union too narrowly against the declared parts type)
- http.ts: cast entry to string | undefined after the Array.isArray
  guard (ReadonlyArray is not narrowed out by Array.isArray, so TS
  kept string | readonly string[] in the else branch)
- _chat.settings.tsx: pass disabled={props.disabled ?? false} to
  SecretSlotRow so the value is always boolean, not boolean | undefined
  (exactOptionalPropertyTypes incompatibility)

Claude-Session: https://claude.ai/code/session_01B95xcqmnLyWiAhApQdjtLC
@github-actions github-actions Bot added size:L vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Jun 19, 2026
@jwangkun

Copy link
Copy Markdown
Collaborator

❌ Changes Requested

This PR has merge conflicts with the base branch and cannot be merged as-is.

Issues:

  1. Merge status: CONFLICTING — Branch has conflicts with main that must be resolved before merging.
  2. Description incomplete — Missing ## Why section per CONTRIBUTING.md conventions.
  3. Diff size: 242 lines — Exceeds the <200 line target; consider splitting if possible.

Action Required:

  • Resolve merge conflicts by rebasing onto main
  • Add a ## Why section to the PR description
  • Consider splitting the PR if feasible

Please update and re-request review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants