From fc37ee5e8bc78893eb5d1065fb8792931c1e010f Mon Sep 17 00:00:00 2001 From: aarbit Date: Mon, 28 Sep 2026 13:43:20 -0500 Subject: [PATCH] Add npm run dev:lan for phone testing over the LAN MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds a dev:lan script (vite --host) so testing on a real device doesn't require permanently changing vite.config.ts's default 127.0.0.1-only binding. Pairs with a small supabaseClient change: when the configured Supabase URL is local (127.0.0.1/localhost), the client now swaps in whatever hostname the page itself was loaded from, so a phone hitting the dev server's LAN IP gets API calls routed to that same IP automatically — no more hand-editing VITE_SUPABASE_URL per network. Never touches a real production Supabase URL. Co-Authored-By: Claude Sonnet 5 Claude-Session: https://claude.ai/code/session_017DUU6CnxECCDeqDNYJgr5x --- package.json | 1 + src/data/supabaseClient.ts | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index e14f8ed..92da0ac 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "type": "module", "scripts": { "dev": "vite", + "dev:lan": "vite --host", "build": "tsc -b && vite build", "lint": "oxlint", "preview": "vite preview", diff --git a/src/data/supabaseClient.ts b/src/data/supabaseClient.ts index d77ac4b..3f3d52c 100644 --- a/src/data/supabaseClient.ts +++ b/src/data/supabaseClient.ts @@ -1,13 +1,27 @@ import { createClient } from '@supabase/supabase-js' -const url = import.meta.env.VITE_SUPABASE_URL +const rawUrl = import.meta.env.VITE_SUPABASE_URL const anonKey = import.meta.env.VITE_SUPABASE_ANON_KEY -if (!url || !anonKey) { +if (!rawUrl || !anonKey) { throw new Error( 'Missing VITE_SUPABASE_URL / VITE_SUPABASE_ANON_KEY. Copy .env.example to .env.local and fill them in ' + '(run `npx supabase start` then `npx supabase status` for local values).', ) } -export const supabase = createClient(url, anonKey) +/** Local Supabase (127.0.0.1/localhost) only: swap in whatever hostname the + * page itself was loaded from. Lets `npm run dev:lan` + a phone on the same + * Wi-Fi work without ever hand-editing VITE_SUPABASE_URL — loading the app + * via the LAN IP makes API calls target that same IP instead of a loopback + * address the phone can't reach. Never touches a real (non-local) + * production URL, so this is a no-op outside local dev. */ +function resolveUrl(value: string): string { + const url = new URL(value) + if (url.hostname === '127.0.0.1' || url.hostname === 'localhost') { + url.hostname = window.location.hostname + } + return url.toString() +} + +export const supabase = createClient(resolveUrl(rawUrl), anonKey)