Skip to content

Commit f6ff4af

Browse files
rlafurudclaude
andcommitted
feat(hybrid): auto-route /launch to localhost when served remotely
If the app is loaded from a remote host (Vercel deploy), launch() now targets http://localhost:8000 automatically — no VITE_LAUNCH_BASE needed. Served from localhost it stays same-origin. Env var still overrides. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 51c1bd9 commit f6ff4af

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

frontend/src/api.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
const BASE = (import.meta.env.VITE_API_BASE ?? '/api').replace(/\/+$/, '')
77

88
// /launch opens the real game on the machine running the backend, so it must
9-
// hit a backend with BAR installed. Defaults to the same backend as everything
10-
// else (local single-process). On a cloud deploy set
11-
// VITE_LAUNCH_BASE=http://localhost:8000 to route launch to the user's own
12-
// local backend while generation stays on the cloud.
13-
const LAUNCH_BASE = (import.meta.env.VITE_LAUNCH_BASE ?? BASE).replace(/\/+$/, '')
9+
// hit a backend with BAR installed. When the app is served from a REMOTE host
10+
// (e.g. the Vercel deploy) we auto-route launch to the user's own local backend
11+
// at http://localhost:8000; when served from localhost we stay same-origin.
12+
// VITE_LAUNCH_BASE overrides this if set.
13+
const _servedRemotely =
14+
typeof window !== 'undefined' &&
15+
!/^(localhost|127\.0\.0\.1|\[::1\])$/.test(window.location.hostname)
16+
const LAUNCH_BASE = (
17+
import.meta.env.VITE_LAUNCH_BASE ?? (_servedRemotely ? 'http://localhost:8000' : BASE)
18+
).replace(/\/+$/, '')
1419

1520
export async function getCatalog() {
1621
const res = await fetch(`${BASE}/catalog`)

0 commit comments

Comments
 (0)