Skip to content

Commit 1c15cef

Browse files
committed
refactor(app): construct server URL with URL
1 parent a5a0a1a commit 1c15cef

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

‎packages/app/src/entry.tsx‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,14 @@ if (!(root instanceof HTMLElement) && import.meta.env.DEV) {
9797
}
9898

9999
const getCurrentUrl = () => {
100-
let serverBaseUrl = import.meta.env.VITE_OPENCODE_SERVER_BASE_URL ?? ""
101-
// Normalizing slashes. Add starting slash if needed, remove trailing slash. Default value will be empty string.
102-
serverBaseUrl = ("/" + serverBaseUrl.replace(/^\//, "")).replace(/\/$/, "")
103100
if (location.hostname.includes("opencode.ai")) return "http://localhost:4096"
104-
if (import.meta.env.DEV)
105-
return `http://${import.meta.env.VITE_OPENCODE_SERVER_HOST ?? "localhost"}:${import.meta.env.VITE_OPENCODE_SERVER_PORT ?? "4096"}${serverBaseUrl}`
106-
return location.origin + serverBaseUrl
101+
const url = new URL(
102+
import.meta.env.DEV
103+
? `http://${import.meta.env.VITE_OPENCODE_SERVER_HOST ?? "localhost"}:${import.meta.env.VITE_OPENCODE_SERVER_PORT ?? "4096"}`
104+
: location.origin,
105+
)
106+
url.pathname = import.meta.env.VITE_OPENCODE_SERVER_BASE_URL ?? ""
107+
return url.href
107108
}
108109

109110
const getDefaultUrl = () => {

0 commit comments

Comments
 (0)