Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

runtimeCaching: urlPattern in json config not properly converted to regex #195

Closed
markbrocato opened this issue Oct 10, 2016 · 2 comments
Closed

Comments

@markbrocato
Copy link

My json config has the following:

  "runtimeCaching": [{
    "urlPattern": "/users\\.json/",
    "handler": "networkFirst",
    "options": {
      "cache": {
        "name": "api"
      }
    }
  }]

which produces:

toolbox.router.get("/users\\.json/", toolbox.networkFirst, {"cache":{"name":"api"}});

It should produce the following, right?

toolbox.router.get(/users\.json/, toolbox.networkFirst, {"cache":{"name":"api"}});

@mactookmyname
Copy link

I ran into this same issue when trying to get setup via CLI and ended up fixing it by converting my config .json into a .js file using module.exports. This allowed the urlPattern field to use an actual RegExp rather than being forced to use a string.

Looking at the cli.js code it seems the file specified as a config is just brought in via require, making this possible.

@jeffposnick
Copy link
Contributor

Thanks for bringing this up. I was toying with the idea of looking at any strings that begin and end with / and implicitly converting them to RegExp objects, but the idea of just promoting JavaScript configuration via module.exports is really a better approach, and should be backwards compatible with people who pass in JSON.

As @mactookmyname mentions, there's no code change needed to the sw-precache command line interface to support this, but I'm going to update the documentation and sample external configuration file to make it clear that the module.exports approach is preferred to JSON.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants