fix: support mobile access when dev server binds to 0.0.0.0#1680
fix: support mobile access when dev server binds to 0.0.0.0#168042tg wants to merge 2 commits intopingdotgg:mainfrom
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 |
c7a2337 to
b41dfb7
Compare
b41dfb7 to
38fd662
Compare
ApprovabilityVerdict: Approved Development tooling change to support mobile device testing when the dev server binds to 0.0.0.0. The changes are limited to Vite config and a simple URL replacement for non-localhost access - no production behavior is affected. You can customize Macroscope's approvability policy. Learn more. |
- Vite server respects T3CODE_HOST for network binding - Skip hardcoded VITE_WS_URL when host is not localhost, letting the client derive WS URL from window.location - HMR auto-detects host when binding to 0.0.0.0
38fd662 to
913863c
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
| // resolved URL with the actual page hostname so the connection reaches the server. | ||
| if (rawUrl.includes("localhost") && window.location.hostname !== "localhost") { | ||
| rawUrl = rawUrl.replace("localhost", window.location.hostname); | ||
| } |
There was a problem hiding this comment.
Naive string replace risks matching localhost in non-hostname positions
Low Severity
rawUrl.includes("localhost") and rawUrl.replace("localhost", ...) perform raw string matching rather than targeting the URL's hostname specifically. Since new URL(rawUrl) is constructed on the very next line, the hostname check and replacement could be done on the parsed URL object (e.g., parsedUrl.hostname === "localhost" and parsedUrl.hostname = window.location.hostname), avoiding any risk of matching "localhost" as a substring in paths, query params, or other hostname parts like notlocalhost.example.com.


Summary
T3CODE_HOSTenv var for network binding (e.g.T3CODE_HOST=0.0.0.0)0.0.0.0instead of hardcodinglocalhostT3CODE_HOSTto turbo.json global env passthroughTest plan
T3CODE_HOST=0.0.0.0 bun devand access from another device on the same networklocalhostbehavior is unchanged whenT3CODE_HOSTis not setNote
Low Risk
Low risk dev-only configuration and URL resolution changes; main risk is misrouting HMR/WebSocket connections when running with custom hosts.
Overview
Improves remote-device access to the dev server by making Vite bind to a configurable host via
T3CODE_HOST(defaulting tolocalhost) and adjusting HMR config to avoid hardcodinglocalhostwhen not running locally.Updates
resolveServerUrlto rewritelocalhostto the currentwindow.location.hostnamewhen the app is accessed from a non-localhost host, ensuring WebSocket connections reach the correct machine. ExposesT3CODE_HOSTthrough TurborepoglobalEnvso the setting propagates in tasks.Written by Cursor Bugbot for commit a2a9afe. This will update automatically on new commits. Configure here.
Note
Fix mobile access when dev server binds to 0.0.0.0
T3CODE_HOSTenv var support to vite.config.ts so the dev server binds to a configurable host (defaultlocalhost). HMR omits an explicit host when not on localhost to allow correct host resolution.resolveServerUrlin utils.ts to replacelocalhostin resolved URLs withwindow.location.hostnamewhen the page is accessed from a non-localhost host.T3CODE_HOSTas a global env var in turbo.json.Macroscope summarized a2a9afe.