Skip to content

fix(hub): serve live previews from a port range Compose can publish - #93

Closed
brianjfox wants to merge 1 commit into
fix/app-reachable-across-sandboxesfrom
fix/live-app-port-range
Closed

brianjfox wants to merge 1 commit into
fix/app-reachable-across-sandboxesfrom
fix/live-app-port-range

Conversation

@brianjfox

Copy link
Copy Markdown
Contributor

Closes #91

Stacked on #72, since the preview needs both to work under Compose; its base should move to main once #72 merges.

What changed

  • apps/hub/src/environment.ts: LIVE_APP_PORTS, a range such as 4100-4119, read as liveAppPorts; absent means any free port, as before. Malformed values refuse startup with a clear message.
  • apps/hub/src/live-app/proxy.ts: serveWithin takes the first free port of the range, skipping ports the other apps hold and ports something else already holds, and fails with live_app_ports_exhausted when none is left. Without a range it binds port 0 as before.
  • apps/hub/src/artifacts/service.ts: when exposing fails, the app is reported as failed with the reason instead of the request failing.
  • deploy/compose.yml: publishes the range on loopback beside the hub's port and passes it to the hub.
  • .env.hub.example and docs/SELF_HOST.md: document the setting and the one-port-per-open-project limit.
  • apps/hub/src/environment.test.ts: covers the parser.

Why

Compose publishes only the hub's port and the two login ports. The proxy's origin for a project's app was the hub's public origin with a random port swapped in, so on 2026-11-02 the preview frame pointed at http://localhost:34141, which the browser could not reach, while the hub inside answered on it. Details in #91.

How it was verified

  • tsc --noEmit -p . passes; oxlint --deny-warnings and Prettier pass on the changed files; environment, live-app and artifacts tests pass (12 tests, 1 new).
  • docker compose config renders LIVE_APP_PORTS=4100-4119 in the hub's environment and publishes the twenty ports.
  • The hub was rebuilt from this branch merged with fix(hub): reach the dev app across the sandbox's network namespaces on Linux #72 on the Compose deployment; see the follow-up note on the PR for what the browser saw.

The live-app proxy gave each project's app a port chosen at random, so
its origin stayed its own and its cookies apart from the hub's. A
deployment that publishes ports, such as Compose, cannot publish a port
it does not know, so from a browser outside the container the preview
never loaded while the hub inside answered on it.

LIVE_APP_PORTS names a range, 4100-4119 by default under Compose, from
which the proxy takes the first free port per project; the Compose file
publishes the range on loopback beside the hub's port and the self-host
docs explain it. Without the setting any free port serves, as on a
developer's machine. With every port of the range in use, the app is
reported as failed with the reason instead of the request failing.

Closes #91

@corbits-triage corbits-triage Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Triage requests changes:

  • Invented fallbacks: added code matches a code pattern
    • apps/hub/src/live-app/proxy.ts:154 empty-fallback: Invented fallback (an empty string, list, object or zero); handle the missing value instead.

@brianjfox

Copy link
Copy Markdown
Contributor Author

Continued, rebased onto main, with the triage finding fixed, in a replacement pull request from branch fix/live-app-port-range-main.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant