Skip to content

Commit 18c5f27

Browse files
committed
fix: support mobile access when dev server binds to 0.0.0.0
- 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
1 parent 0f67492 commit 18c5f27

3 files changed

Lines changed: 11 additions & 8 deletions

File tree

apps/web/src/lib/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,19 @@ export const resolveServerUrl = (options?: {
5252
pathname?: string | undefined;
5353
searchParams?: Record<string, string> | undefined;
5454
}): string => {
55-
const rawUrl = firstNonEmptyString(
55+
let rawUrl = firstNonEmptyString(
5656
options?.url,
5757
window.desktopBridge?.getWsUrl(),
5858
import.meta.env.VITE_WS_URL,
5959
window.location.origin,
6060
);
6161

62+
// When accessing from a remote host (e.g. mobile), replace localhost in the
63+
// resolved URL with the actual page hostname so the connection reaches the server.
64+
if (rawUrl.includes("localhost") && window.location.hostname !== "localhost") {
65+
rawUrl = rawUrl.replace("localhost", window.location.hostname);
66+
}
67+
6268
const parsedUrl = new URL(rawUrl);
6369
if (options?.protocol) {
6470
parsedUrl.protocol = options.protocol;

apps/web/vite.config.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { defineConfig } from "vite";
66
import pkg from "./package.json" with { type: "json" };
77

88
const port = Number(process.env.PORT ?? 5733);
9+
const host = process.env.T3CODE_HOST ?? "localhost";
910
const sourcemapEnv = process.env.T3CODE_WEB_SOURCEMAP?.trim().toLowerCase();
1011

1112
const buildSourcemap =
@@ -42,14 +43,9 @@ export default defineConfig({
4243
},
4344
server: {
4445
port,
46+
host,
4547
strictPort: true,
46-
hmr: {
47-
// Explicit config so Vite's HMR WebSocket connects reliably
48-
// inside Electron's BrowserWindow. Vite 8 uses console.debug for
49-
// connection logs — enable "Verbose" in DevTools to see them.
50-
protocol: "ws",
51-
host: "localhost",
52-
},
48+
hmr: host === "localhost" ? { protocol: "ws", host: "localhost" } : { protocol: "ws" },
5349
},
5450
build: {
5551
outDir: "dist",

turbo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"T3CODE_HOME",
1313
"T3CODE_AUTH_TOKEN",
1414
"T3CODE_DESKTOP_WS_URL",
15+
"T3CODE_HOST",
1516
"T3CODE_TRACE_MIN_LEVEL",
1617
"T3CODE_TRACE_TIMING_ENABLED",
1718
"T3CODE_TRACE_FILE",

0 commit comments

Comments
 (0)