Ignoring certain Url path-names in Service Worker for Create React App

1.7k Views Asked by At

the url that is ignored by default in Create React App Service Worker is the following for firebase auth "__" urls, it is done like so:

navigateFallbackWhitelist: [/^(?!\/__).*/]

**using the same negative Regex method I tried adding to the array the following, "/dynamicHosting": **

Like so:

navigateFallbackWhitelist: [/^(?!\/__).*/, /^(?!\/dynamicHosting).*/]**

Problem is that Service Worker still keeps intercepting the path "/dynamicHosting"

Thus the 200.html my default navigateFallback file renders. instead of dynamic html file from my server.

Why is the ServiceWorker not ignoring the path "/dynamicHosting".

I am using SW-Precache CLI like so without ejecting from Create React App:

"build": "react-scripts build && sw-precache --config=sw-precache-config.js

Where the sw-precache-config.js looks like so:

module.exports = {
  staticFileGlobs: [
    './build/**/**.html',
    './build/images/**',
    './build/static/**',
    './build/manifest.json',
  ],
  dontCacheBustUrlsMatching: /\.\w{8}\./,
  swFilePath: './build/service-worker.js',
      // For unknown URLs, fallback to the index page
  navigateFallback: './200.html',
      // Ignores URLs starting from /__ (useful for Firebase):
  navigateFallbackWhitelist: [/^(?!\/__).*/, /^(?!\/dynamicHosting).*/],
  staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/, /404\.html$/],
  stripPrefix: './build'
}

UPDATE:

instead of a comma I had to write up the navigateFallbackWhitelist like so to combine the Regex:

after the following change it works:

navigateFallbackWhitelist: [/^(?!\/__).*/+ "|" +/^(?!\/dynamicHosting).*/],

0

There are 0 best solutions below