From 3ed3d5aba4f6f23100a5561c12eb4d1483751e58 Mon Sep 17 00:00:00 2001 From: sergesoroka Date: Sun, 6 Oct 2024 17:13:56 +0300 Subject: [PATCH] scope BASE_URL from .env --- src/App.jsx | 3 ++- src/main.jsx | 10 ++++++---- utils/base64.js | 19 ------------------- 3 files changed, 8 insertions(+), 24 deletions(-) delete mode 100644 utils/base64.js diff --git a/src/App.jsx b/src/App.jsx index cedffad..5b426fa 100755 --- a/src/App.jsx +++ b/src/App.jsx @@ -26,12 +26,13 @@ function App() { const token = keycloak.token ? keycloak.token : stored_token; if (navigator.serviceWorker.controller) { + console.log("post message", navigator.serviceWorker); + navigator.serviceWorker.controller.postMessage({ type: "SET_TOKEN", token: token, }); } - useEffect(() => { if (keycloak.authenticated) { localStorage.setItem("refreshToken", keycloak.refreshToken); diff --git a/src/main.jsx b/src/main.jsx index 7f28878..5d026f3 100755 --- a/src/main.jsx +++ b/src/main.jsx @@ -17,15 +17,17 @@ const router = createBrowserRouter( { basename: "/search" } ); +console.log(import.meta.env.BASE_URL); + const base_url = import.meta.env.PROD ? "/search/worker.js" : "/worker.js"; -const scope_url = import.meta.env.PROD - ? "https://spectra-dev.adma.ai/search/" - : "http://localhost:5173/search/"; +// const scope_url = import.meta.env.PROD +// ? "https://spectra-dev.adma.ai/search/" +// : "http://localhost:5173/search/"; if ("serviceWorker" in navigator) { window.addEventListener("load", () => { navigator.serviceWorker - .register(base_url, { scope: scope_url }) + .register(base_url, { scope: `${import.meta.env.BASE_URL}` }) .then((registration) => { console.log( "Service Worker registered with scope: ", diff --git a/utils/base64.js b/utils/base64.js deleted file mode 100644 index ce8402b..0000000 --- a/utils/base64.js +++ /dev/null @@ -1,19 +0,0 @@ -// src/utils/base64.js - -// Function to decode base64 string and convert it to a Blob -export function base64ToBlob(base64, contentType = "", sliceSize = 512) { - const byteCharacters = atob(base64); - const byteArrays = []; - - for (let offset = 0; offset < byteCharacters.length; offset += sliceSize) { - const slice = byteCharacters.slice(offset, offset + sliceSize); - const byteNumbers = new Array(slice.length); - for (let i = 0; i < slice.length; i++) { - byteNumbers[i] = slice.charCodeAt(i); - } - const byteArray = new Uint8Array(byteNumbers); - byteArrays.push(byteArray); - } - - return new Blob(byteArrays, { type: contentType }); -}