From 153696416517e3fcea5317cb8c0ca6485f1e896a Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Sun, 4 Feb 2024 22:13:33 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=8B=20Adds=20location=20for=20socket?= =?UTF-8?q?=20connection?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/App.svelte | 10 +++++----- app/src/lib/location.ts | 7 ++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/app/src/App.svelte b/app/src/App.svelte index 0de1362..b598616 100644 --- a/app/src/App.svelte +++ b/app/src/App.svelte @@ -6,13 +6,13 @@ import Controller from './routes/Controller.svelte'; import Config from './routes/Config.svelte'; import Health from './routes/SystemHealth.svelte'; - import location from './lib/location'; import Sidebar from './components/Sidebar.svelte'; import FileCache from './lib/cache'; + import { socketLocation } from './lib/location'; - export let url = window.location.pathname; + export let url = window.location.pathname onMount(() => { - connect(`ws://${location}`); + connect(socketLocation); registerFetchIntercept() }); @@ -21,9 +21,9 @@ window.fetch = async (...args) => { const [resource, config] = args; await FileCache.openDatabase(); - let file; + let file: BodyInit | Uint8Array | undefined | null; try { - file = await FileCache.getFile(resource.url); + file = await FileCache.getFile(resource.toString()); } catch (error) { console.log(error); } diff --git a/app/src/lib/location.ts b/app/src/lib/location.ts index dfb142e..6c00c47 100644 --- a/app/src/lib/location.ts +++ b/app/src/lib/location.ts @@ -1,3 +1,8 @@ -const location = import.meta.env.DEV ? "leika.local" : window.location.host +const forWeb = import.meta.env.MODE === "WEB" +const mock = import.meta.env.MODE === "MOCK" + +const location = mock ? `${window.location.hostname}:2096` : "leika.local" + +export const socketLocation = forWeb ? `wss://${window.location.hostname}:2096` : `ws://${location}` export default location; \ No newline at end of file