From e0a386cfb0be01b5f48f6b340256219f2f03e770 Mon Sep 17 00:00:00 2001 From: twsl <45483159+twsl@users.noreply.github.com> Date: Sat, 19 Feb 2022 14:58:36 +0000 Subject: [PATCH] Modify changes to match current code --- app/packages/app/src/components/Flashlight.tsx | 11 ++++++++++- .../app/src/components/ViewBar/viewBarMachine.ts | 2 +- app/packages/app/src/recoil/selectors.ts | 4 ++-- app/packages/app/src/shared/connection.ts | 12 ++++++------ 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/app/packages/app/src/components/Flashlight.tsx b/app/packages/app/src/components/Flashlight.tsx index e31d0d15d6..13db9e1a4a 100644 --- a/app/packages/app/src/components/Flashlight.tsx +++ b/app/packages/app/src/components/Flashlight.tsx @@ -52,7 +52,16 @@ export let sampleIndices = new Map(); let nextIndex = 0; let lookers = createLookerCache(); -const url = `${http}page?`; +const url = (() => { + let origin = window.location.origin; + try { + // @ts-ignore + if (import.meta.env.DEV) { + origin = "http://localhost:5151"; + } + } catch {} + return `${http}/page?`; +})(); const Container = styled.div` width: 100%; diff --git a/app/packages/app/src/components/ViewBar/viewBarMachine.ts b/app/packages/app/src/components/ViewBar/viewBarMachine.ts index 48ec62a54a..6e7ca01956 100644 --- a/app/packages/app/src/components/ViewBar/viewBarMachine.ts +++ b/app/packages/app/src/components/ViewBar/viewBarMachine.ts @@ -37,7 +37,7 @@ export const createStage = ( }); function getStageInfo(context) { - return fetch(`${context.http}stages`).then((response) => response.json()); + return fetch(`${context.http}/stages`).then((response) => response.json()); } function serializeStage(stage, stageMap, fieldNames) { diff --git a/app/packages/app/src/recoil/selectors.ts b/app/packages/app/src/recoil/selectors.ts index 53d19990a8..6e878f0cf0 100644 --- a/app/packages/app/src/recoil/selectors.ts +++ b/app/packages/app/src/recoil/selectors.ts @@ -49,7 +49,7 @@ export const fiftyone = selector({ let response = null; do { try { - response = await (await fetch(`${http}fiftyone`)).json(); + response = await (await fetch(`${http}/fiftyone`)).json(); } catch {} if (response) break; await new Promise((r) => setTimeout(r, 2000)); @@ -66,7 +66,7 @@ export const showTeamsButton = selector({ const storedTeams = window.localStorage.getItem("fiftyone-teams"); if (storedTeams) { window.localStorage.removeItem("fiftyone-teams"); - fetch(`${http}teams?submitted=true`, { method: "post" }); + fetch(`${http}/teams?submitted=true`, { method: "post" }); } if ( teams.submitted || diff --git a/app/packages/app/src/shared/connection.ts b/app/packages/app/src/shared/connection.ts index 38c45108b1..a17fff33b9 100644 --- a/app/packages/app/src/shared/connection.ts +++ b/app/packages/app/src/shared/connection.ts @@ -105,9 +105,7 @@ export const handleId = new URLSearchParams(window.location.search).get( export const sessionId = uuid(); const host = import.meta.env.DEV ? "localhost:5151" : window.location.host; -const path = - window.location.pathname + - (window.location.pathname.endsWith("/") ? "" : "/"); +const path = window.location.pathname.endsWith("/") ? window.location.pathname.slice(0, -1) : window.location.pathname; export const port = isElectron() ? parseInt(process.env.FIFTYONE_SERVER_PORT) || 5151 @@ -122,19 +120,21 @@ export const http = isElectron() : window.location.protocol + "//" + host + path; export const ws = isElectron() - ? `ws://${address}:${port}${path}state` + ? `ws://${address}:${port}${path}/state` : `${ window.location.protocol === "https:" ? "wss:" : "ws:" - }//${host}${path}state`; + }//${host}${path}/state`; export const appContext = isElectron() ? "desktop" : isColab ? "colab" + : isDatabricks + ? "databricks" : isNotebook ? "notebook" : "browser"; export default polling - ? new HTTPSSocket(`${http}polling?sessionId=${sessionId}`) + ? new HTTPSSocket(`${http}/polling?sessionId=${sessionId}`) : new ReconnectingWebSocket(ws);