From f608bfac62e94fc19ef5f60133beda0800aa14b9 Mon Sep 17 00:00:00 2001 From: Hang Date: Fri, 30 Aug 2024 14:21:37 +0800 Subject: [PATCH] Fix ServiceWorker scope with BASE_PATH. When BASE_PATH is specified to host UI in subpath, ServiceWorkers refuse to work due to mismatching scope. This can be verified through error logs in Chrome devtools on landing page. --- src/shared/workers/serviceWorker.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/shared/workers/serviceWorker.ts b/src/shared/workers/serviceWorker.ts index e03a7d85c9..d9631f74f2 100644 --- a/src/shared/workers/serviceWorker.ts +++ b/src/shared/workers/serviceWorker.ts @@ -1,3 +1,5 @@ +import {BASE_PATH} from 'src/shared/constants' + export const registerServiceWorker = (): Promise => { // Worker -- load prior to page load event, in order to intercept fetch in http/2. // see service worker life cycle. https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers @@ -7,7 +9,7 @@ export const registerServiceWorker = (): Promise => { // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore new URL('../workers/downloadHelper.ts', import.meta.url), - {scope: '/api/v2/query'} + {scope: `${BASE_PATH}api/v2/query`} /* webpackChunkName: "interceptor" */ ) } @@ -25,7 +27,7 @@ export const registerServiceWorkerInfluxQL = // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore new URL('../workers/downloadHelper.ts', import.meta.url), - {scope: '/query'} + {scope: `${BASE_PATH}query`} /* webpackChunkName: "interceptor" */ ) } @@ -43,7 +45,7 @@ export const registerServiceWorkerSQL = // eslint-disable-next-line @typescript-eslint/ban-ts-comment // @ts-ignore new URL('../workers/downloadHelper.ts', import.meta.url), - {scope: '/api/v2private/query'} + {scope: `${BASE_PATH}api/v2private/query`} /* webpackChunkName: "interceptor" */ ) }