From 287a5b3bff7ddf36e292c8e73c0d0589eee3a417 Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Wed, 26 Jun 2024 16:51:04 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7(service-worker)=20add=20conf=20fil?= =?UTF-8?q?e=20with=20dev=20urls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a conf files to the service worker to store the development urls. If someone wants to change the urls, they can do it in the conf file, it is more intuitive than changing the urls in the service worker file. --- .../apps/impress/src/core/service-worker/conf.ts | 5 +++++ .../impress/src/core/service-worker/service-worker.ts | 9 ++------- 2 files changed, 7 insertions(+), 7 deletions(-) create mode 100644 src/frontend/apps/impress/src/core/service-worker/conf.ts diff --git a/src/frontend/apps/impress/src/core/service-worker/conf.ts b/src/frontend/apps/impress/src/core/service-worker/conf.ts new file mode 100644 index 00000000..de6b240f --- /dev/null +++ b/src/frontend/apps/impress/src/core/service-worker/conf.ts @@ -0,0 +1,5 @@ +export const SW_DEV_URL = [ + 'http://localhost:3000', + 'https://impress.127.0.0.1.nip.io', + 'https://impress-staging.beta.numerique.gouv.fr', +]; diff --git a/src/frontend/apps/impress/src/core/service-worker/service-worker.ts b/src/frontend/apps/impress/src/core/service-worker/service-worker.ts index b661d776..a806726a 100644 --- a/src/frontend/apps/impress/src/core/service-worker/service-worker.ts +++ b/src/frontend/apps/impress/src/core/service-worker/service-worker.ts @@ -19,6 +19,7 @@ import { // eslint-disable-next-line import/order import { ApiPlugin } from './ApiPlugin'; +import { SW_DEV_URL } from './conf'; import { isApiUrl } from './service-worker-api'; // eslint-disable-next-line import/order @@ -50,13 +51,7 @@ const getCacheNameVersion = (cacheName: string) => const getStrategy = ( options?: NetworkFirstOptions | StrategyOptions, ): NetworkFirst | CacheFirst => { - const devDomains = [ - 'http://localhost:3000', - 'https://impress.127.0.0.1.nip.io', - 'https://impress-staging.beta.numerique.gouv.fr', - ]; - - return devDomains.some((devDomain) => + return SW_DEV_URL.some((devDomain) => self.location.origin.includes(devDomain), ) ? new NetworkFirst(options)