diff --git a/packages/app/src/runtime/platform/web.ts b/packages/app/src/runtime/platform/web.ts index bd48f32a214..43bb69363ae 100644 --- a/packages/app/src/runtime/platform/web.ts +++ b/packages/app/src/runtime/platform/web.ts @@ -54,8 +54,12 @@ export function createWebPlatform(version: string) { function getCurrentServerUrl() { if (import.meta.env.VITE_OPENCODE_SERVER_MODE === "none") return undefined - if (import.meta.env.DEV) - return `http://${import.meta.env.VITE_OPENCODE_SERVER_HOST ?? "localhost"}:${import.meta.env.VITE_OPENCODE_SERVER_PORT ?? "4096"}` + if (import.meta.env.DEV) { + const loopback = + location.hostname === "localhost" || location.hostname === "[::1]" || location.hostname.startsWith("127.") + const host = import.meta.env.VITE_OPENCODE_SERVER_HOST ?? (loopback ? location.hostname : "localhost") + return `http://${host}:${import.meta.env.VITE_OPENCODE_SERVER_PORT ?? "4096"}` + } return location.origin }