From 9966d8eb65633d2e285367b67fb49688dcd859e9 Mon Sep 17 00:00:00 2001 From: Brendan Allan Date: Thu, 12 Jan 2023 18:18:31 +0800 Subject: [PATCH] use origin instead of url for web --- apps/web/src/App.tsx | 11 +++++++---- apps/web/src/env.d.ts | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/web/src/App.tsx b/apps/web/src/App.tsx index 036dd00cd..a4a534684 100644 --- a/apps/web/src/App.tsx +++ b/apps/web/src/App.tsx @@ -1,12 +1,14 @@ -import { createWSClient, loggerLink, splitLink, wsLink } from '@rspc/client'; +import { createWSClient, loggerLink, wsLink } from '@rspc/client'; import { getDebugState, hooks, queryClient } from '@sd/client'; import SpacedriveInterface, { Platform, PlatformProvider } from '@sd/interface'; import { useEffect } from 'react'; globalThis.isDev = import.meta.env.DEV; +const serverOrigin = import.meta.env.VITE_SDSERVER_ORIGIN || 'localhost:8080'; + const wsClient = createWSClient({ - url: import.meta.env.VITE_SDSERVER_BASE_URL || 'ws://localhost:8080/rspc/ws' + url: `ws://${serverOrigin}/rspc/ws` }); const client = hooks.createClient({ @@ -20,11 +22,12 @@ const client = hooks.createClient({ ] }); +const http = isDev ? 'http' : 'https'; + const platform: Platform = { platform: 'web', getThumbnailUrlById: (casId) => - `${import.meta.env.VITE_SDSERVER_BASE_URL || 'http://localhost:8080' - }/spacedrive/thumbnail/${encodeURIComponent(casId)}.webp`, + `${http}://${serverOrigin}/spacedrive/thumbnail/${encodeURIComponent(casId)}.webp`, openLink: (url) => window.open(url, '_blank')?.focus(), demoMode: true }; diff --git a/apps/web/src/env.d.ts b/apps/web/src/env.d.ts index 06e6e15b4..7bda043d8 100644 --- a/apps/web/src/env.d.ts +++ b/apps/web/src/env.d.ts @@ -1,7 +1,7 @@ /// interface ImportMetaEnv { - readonly VITE_SDSERVER_BASE_URL: string; + readonly VITE_SDSERVER_ORIGIN: string; } interface ImportMeta {