From c65c4a3d3225280d7898e2f4ca39c4895144dbbb Mon Sep 17 00:00:00 2001 From: Laurent Caouissin <38245508+laurentC35@users.noreply.github.com> Date: Wed, 16 Oct 2024 17:04:49 +0200 Subject: [PATCH] feat(#231): add external service-worker in condition where VITE_EXTERNAL_RESOURCES_URL is defined (#252) fix: #231 --- drama-queen/src/queen-service-worker.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drama-queen/src/queen-service-worker.js b/drama-queen/src/queen-service-worker.js index 39ad99e8..50d45c4c 100644 --- a/drama-queen/src/queen-service-worker.js +++ b/drama-queen/src/queen-service-worker.js @@ -6,9 +6,27 @@ importScripts( 'https://storage.googleapis.com/workbox-cdn/releases/7.1.0/workbox-sw.js' ) +/** + * Load all functions needed by all service-workers + */ const { CacheableResponsePlugin } = workbox.cacheableResponse const { registerRoute } = workbox.routing const { NetworkFirst, CacheFirst } = workbox.strategies +const { RangeRequestsPlugin } = workbox.rangeRequests + +/** + * Load env variable with swEnv.js (manage by vite-envs plugin) + */ +importScripts(`${self._DRAMAQUEEN_URL}/swEnv.js`) + +/** + * Load external resource service-worker + */ +if (self.__VITE_ENVS.VITE_EXTERNAL_RESOURCES_URL) { + // In external service-worker, self._QUEEN_CAPMI_URL has to be defined to get root url of externalResourcesUrl + self._QUEEN_CAPMI_URL = self.__VITE_ENVS.VITE_EXTERNAL_RESOURCES_URL + importScripts(`${self._QUEEN_CAPMI_URL}/queen-service-worker.js`) +} const getDramaQueenUrlRegex = (url) => { return url