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
This commit is contained in:
Tobias Henkel 2018-10-10 22:03:11 +02:00
parent be64ed2777
commit 3155b12f57
No known key found for this signature in database
GPG Key ID: 03750DEC158E5FA2
2 changed files with 9 additions and 0 deletions

View File

@ -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.

View File

@ -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)