Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass a new sameOrigin param to matchCallback #2487

Closed
jeffposnick opened this issue May 1, 2020 · 2 comments
Closed

Pass a new sameOrigin param to matchCallback #2487

jeffposnick opened this issue May 1, 2020 · 2 comments

Comments

@jeffposnick
Copy link
Contributor

In the course of #2486 I realized there are a lot of places where I end up writing url.origin === self.location.origin && ....

We could simplify this use case by passing in an additional parameter to the matchCallback function, sameOrigin, that's set to the result of evaluating url.origin === self.location.origin inside of the Router.

@dman777
Copy link

dman777 commented May 19, 2020

I am having a similar issue.

The front end web app is https://bar-1.dev.foo.io/ but api calls(which I am trying to cache) are made to https://bar-api-1.dev.foo.io/v1/bedlist_providers?size=16.

The service worker runs with no complaints. It's just not caching the api as it should:

registerRoute(
  /v1\/bedlist_providers\?size=/,
  new StaleWhileRevalidate({
    cacheName: 'providers-list'
  }),
);

registerRoute(
  /v1\/providers\/\d*\/bedlist\?size=/,
  new StaleWhileRevalidate({
    cacheName: 'bedlists'
  }),

I believe it is because the api route origin is different than what it is registered to. Any ideas what I can do?

@jeffposnick
Copy link
Contributor Author

You can use a matchCallback as the first parameter to registerRoute() instead of a RegExp. That would probably end up being a lot cleaner for your use case.

registerRoute(
  ({url}) => url.origin === 'https://bar-api-1.dev.foo.io' &&
             url.pathname === '/v1/bedlist_providers',
  new StaleWhileRevalidate({
    cacheName: 'providers-list'
  }),
);

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

No branches or pull requests

2 participants