From 3155b12f574a6cc9e43454f36084ffa8f76c4bbc Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Wed, 10 Oct 2018 22:03:11 +0200 Subject: [PATCH] Optionally disable service worker in zuul-web In some cases we need to disable the service worker which does advanced caching. For example this is the case when using a redirect-based authentication proxy in front of zuul. In this case it can be that the main page is serviced by the service worker without the option to prevent that with cache headers. When that happens the first request that hits the server and gets redirected to a login page is an api request. This breaks zuul-web completely until the browser cache is cleared. A solution to this problem is to optionally disable the service worker. This makes it possible to disable caching of any entry pages forcing the redirect to happen before any api requests. This change makes it possible to disable the service worker at compile time by setting the REACT_APP_DISABLE_SERVICE_WORKER=true variable without the need of on-the-fly patching of zuul itself before installation. Change-Id: I537b2c43b556cf2c3696683bf10dd06e152ec11f --- doc/source/developer/javascript.rst | 4 ++++ web/src/registerServiceWorker.js | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/doc/source/developer/javascript.rst b/doc/source/developer/javascript.rst index 7a1c5d3975..b471f7dfac 100644 --- a/doc/source/developer/javascript.rst +++ b/doc/source/developer/javascript.rst @@ -192,3 +192,7 @@ As long as `yarn`_ is installed, the installation of zuul will run .. _React: https://reactjs.org/ .. _Patternfly: https://www.patternfly.org/ .. _create-react-app: https://github.com/facebook/create-react-app/blob/master/packages/react-scripts/template/README.md + +In some cases there is the need to disable the service worker which does +advanced caching. In order to do that set the environment variable +``REACT_APP_DISABLE_SERVICE_WORKER=true`` during installation. diff --git a/web/src/registerServiceWorker.js b/web/src/registerServiceWorker.js index 4f95314426..3180adeb70 100644 --- a/web/src/registerServiceWorker.js +++ b/web/src/registerServiceWorker.js @@ -21,6 +21,11 @@ const isLocalhost = Boolean( ) export default function register () { + if (process.env.REACT_APP_DISABLE_SERVICE_WORKER === 'true') { + console.log('Disabled service worker') + return + } + if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { // The URL constructor is available in all browsers that support SW. const publicUrl = new URL(process.env.PUBLIC_URL, window.location)