fix(app): memory leak with platform fetch for events
This commit is contained in:
@@ -12,10 +12,19 @@ export const { use: useGlobalSDK, provider: GlobalSDKProvider } = createSimpleCo
|
|||||||
const platform = usePlatform()
|
const platform = usePlatform()
|
||||||
const abort = new AbortController()
|
const abort = new AbortController()
|
||||||
|
|
||||||
|
const auth = (() => {
|
||||||
|
if (typeof window === "undefined") return
|
||||||
|
const password = window.__OPENCODE__?.serverPassword
|
||||||
|
if (!password) return
|
||||||
|
return {
|
||||||
|
Authorization: `Basic ${btoa(`opencode:${password}`)}`,
|
||||||
|
}
|
||||||
|
})()
|
||||||
|
|
||||||
const eventSdk = createOpencodeClient({
|
const eventSdk = createOpencodeClient({
|
||||||
baseUrl: server.url,
|
baseUrl: server.url,
|
||||||
signal: abort.signal,
|
signal: abort.signal,
|
||||||
fetch: platform.fetch,
|
headers: auth,
|
||||||
})
|
})
|
||||||
const emitter = createGlobalEmitter<{
|
const emitter = createGlobalEmitter<{
|
||||||
[key: string]: Event
|
[key: string]: Event
|
||||||
|
|||||||
@@ -78,6 +78,9 @@ export namespace Server {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.use((c, next) => {
|
.use((c, next) => {
|
||||||
|
// Allow CORS preflight requests to succeed without auth.
|
||||||
|
// Browser clients sending Authorization headers will preflight with OPTIONS.
|
||||||
|
if (c.req.method === "OPTIONS") return next()
|
||||||
const password = Flag.OPENCODE_SERVER_PASSWORD
|
const password = Flag.OPENCODE_SERVER_PASSWORD
|
||||||
if (!password) return next()
|
if (!password) return next()
|
||||||
const username = Flag.OPENCODE_SERVER_USERNAME ?? "opencode"
|
const username = Flag.OPENCODE_SERVER_USERNAME ?? "opencode"
|
||||||
@@ -107,7 +110,12 @@ export namespace Server {
|
|||||||
|
|
||||||
if (input.startsWith("http://localhost:")) return input
|
if (input.startsWith("http://localhost:")) return input
|
||||||
if (input.startsWith("http://127.0.0.1:")) return input
|
if (input.startsWith("http://127.0.0.1:")) return input
|
||||||
if (input === "tauri://localhost" || input === "http://tauri.localhost") return input
|
if (
|
||||||
|
input === "tauri://localhost" ||
|
||||||
|
input === "http://tauri.localhost" ||
|
||||||
|
input === "https://tauri.localhost"
|
||||||
|
)
|
||||||
|
return input
|
||||||
|
|
||||||
// *.opencode.ai (https only, adjust if needed)
|
// *.opencode.ai (https only, adjust if needed)
|
||||||
if (/^https:\/\/([a-z0-9-]+\.)*opencode\.ai$/.test(input)) {
|
if (/^https:\/\/([a-z0-9-]+\.)*opencode\.ai$/.test(input)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user