Skip to content

/exec-ws SSE subscriptions publish loopback helper URLs for LAN viewers #92

Description

@mwolson

Summary

LAN or remote viewers can load the serve-sim UI through a host such as minipro24.lan, but the preview can switch back to loopback helper URLs after the UI subscribes to /api/events through /exec-ws.

Environment

  • Observed with serve-sim@0.1.41
  • Upstream main contains the same source behavior before the proposed fix
  • macOS on Apple Silicon
  • Xcode 26.5
  • Browser running from another LAN machine or a remote browser preview

Steps to reproduce

  1. Start serve-sim on all interfaces:

    npx --yes serve-sim@0.1.41 "iPhone 17" --port 3200 --host 0.0.0.0
  2. Open the UI from another machine:

    http://minipro24.lan:3200
    
  3. Observe that the initial HTML config can contain the LAN host.

  4. Wait for the UI to subscribe to /api/events through /exec-ws.

Expected behavior

The /api/events preview config keeps helper URLs reachable by the remote viewer, for example:

http://minipro24.lan:3100/stream.mjpeg
ws://minipro24.lan:3100/ws

Actual behavior

The browser starts retrying loopback helper URLs, for example:

http://127.0.0.1:3100/stream.mjpeg?raw=1
ws://127.0.0.1:3100/ws

A direct request to http://minipro24.lan:3200/api/events returns the expected LAN host, so the issue appears specific to the /exec-ws SSE proxy path.

Root cause

packages/serve-sim/src/exec-ws.ts proxies allowed SSE subscriptions by making a loopback httpRequest to 127.0.0.1:<serverPort>, but it does not forward the viewer's original Host header.

That means /api/events sees a loopback request, so rewriteStateForRequestHost treats it as local and leaves the helper URLs on 127.0.0.1.

Related work

Proposed fix

I have a small PR ready that forwards the WebSocket upgrade Host header into allowed SSE loopback requests and adds regression coverage for both LAN and loopback preview config URLs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions