Fix primary environment origin on LAN web UI#3737
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Needs human review This PR modifies the primary environment target resolution logic that determines HTTP/WS connection routing. While it's a focused fix for LAN access scenarios, the change to networking behavior and the author's limited history with this file warrants human verification. You can customize Macroscope's approvability policy. Learn more. |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
6ee6fdd to
1b02af1
Compare
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
What Changed
Primary-environment requests are still resolving to loopback (127.0.0.1) in LAN-access scenarios. When the WebUI is opened via a LAN host/IP, those loopback-bound calls target the client machine instead of the actual backend host, so key API/bootstrap requests fail. This fix forces request origin resolution to follow the active LAN origin, restoring WebUI reachability over LAN.
Why
To make T3Code work over LAN adress
UI Changes
N/A
Screenshots / How to replicate problem
The problem can be found when enabling network access, generating a new token and trying to use the LAN adress. You will then be shown the following promt:
And when checking network debug in chrome:

Checklist
Note
Medium Risk
Changes bootstrap URL selection for all clients; wrong hostname/protocol edge cases could misroute API/WS, but scope is limited to loopback-vs-network origin logic with new tests.
Overview
Fixes primary environment API/WebSocket base URLs when the Web UI is opened on a LAN host while build-time config still points at loopback (
127.0.0.1).readPrimaryEnvironmentTargetintarget.tsno longer always uses a configured loopback target. If the page is loaded over http/https on a non-loopback hostname and the configured HTTP base is loopback, resolution switches to the browser window origin (same for the no-config path before desktop-managed fallback). Desktop and existing Vite dev-server proxy behavior stay gated on loopback/window checks.Tests add env stubs in
bootstrap.test.ts, a LAN-vs-VITE_HTTP_URLcase, stronger assertions for desktop-managed targets, and at3code-dev://window origin for the missing-endpoint test.Reviewed by Cursor Bugbot for commit d4b0be3. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix primary environment origin to prefer network host over loopback config in LAN web UI
shouldPreferWindowOriginOverConfiguredTargetintarget.tsto detect when the page is served from a non-loopback HTTP/HTTPS host while the configured target points to a loopback address.readPrimaryEnvironmentTargetprecedence: non-loopback window origins now override a configured loopback target, fixing LAN access where the browser's actual host was ignored in favor of a localhost config.readPrimaryEnvironmentTargetmay now return the window-origin target instead of a configured loopback target when accessed from a non-loopback host.Macroscope summarized d4b0be3.