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

ExpressRoute, RegExpRoute, backgroundSync are undefined in workbox-sw #634

Closed
jmtt89 opened this issue Jun 14, 2017 · 3 comments
Closed

Comments

@jmtt89
Copy link

jmtt89 commented Jun 14, 2017

Library Affected:
workbox-sw

Browser & Platform:
all browsers

Issue or Feature Request Description:
Don't find reference inside the exported object to this class:
ExpressRoute, RegExpRoute, backgroundSync

i check the code and the class ExpressRoute and RegExpRoute exist but with other name (RegExpRoute$1 and ExpressRoute$1) but not are exported.

When reporting bugs, please include relevant JavaScript Console logs and links to public URLs at which the issue could be reproduced.

//My Service-Worker.js

import * as worker from 'workbox-sw';
const workboxSW = new worker.default();
workboxSW.precache([...]);

//backgroundSync
let bgQueue = workboxSW.backgroundSync.QueuePlugin();

// Network Stategies
const networkFirst = workboxSW.strategies.networkFirst({
  networkTimeoutSeconds: 5
});
const networkOnly = workboxSW.strategies.networkOnly({
  plugins: [bgQueue]
});
const cacheFirst = workboxSW.strategies.cacheFirst();

//RuntimeCache
workboxSW.router.registerRoutes({
  routes: [
    new workboxSW.routing.RegExpRoute({
      regExp: new RegExp('^https://fonts.googleapis.com/*'),
      handler: cacheFirst
    }),
    new workboxSW.routing.RegExpRoute({
      regExp: new RegExp('^https://code.jquery.com/*'),
      handler: cacheFirst
    }),
    //My custom Route
    new workboxSW.routing.ExpressRoute({
      path: '/my/route/:id',
      handler: networkFirst,
      method: 'POST'
    })
 ]
});

Errors:
backgroundSync and routing( RegExpRoute and ExpressRoute container object) are undefined

@mikefowler
Copy link

@jmtt89 I believe this is expected, in the current implementation. If you want access to the low-level route classes you need to import the workbox-routing package and access them via the workbox global. The classes are included in workbox-sw but are not available publicly on the instance.

@mikefowler
Copy link

import * as worker from 'workbox-sw';
import 'workbox-routing';

const workboxSW = new worker.default();

workboxSW.precache([...]);

let bgQueue = workboxSW.backgroundSync.QueuePlugin();

const networkFirst = workboxSW.strategies.networkFirst({
  networkTimeoutSeconds: 5
});

const networkOnly = workboxSW.strategies.networkOnly({
  plugins: [bgQueue]
});

const cacheFirst = workboxSW.strategies.cacheFirst();

workboxSW.router.registerRoutes({
  routes: [
    new workbox.routing.RegExpRoute({
      regExp: new RegExp('^https://fonts.googleapis.com/*'),
      handler: cacheFirst
    }),
    new workbox.routing.RegExpRoute({
      regExp: new RegExp('^https://code.jquery.com/*'),
      handler: cacheFirst
    }),
    //My custom Route
    new workbox.routing.ExpressRoute({
      path: '/my/route/:id',
      handler: networkFirst,
      method: 'POST'
    })
 ]
});

@jmtt89
Copy link
Author

jmtt89 commented Jun 15, 2017

ohhh, I did not see that in the documentation, thanks, I will close this 👍 😄

@jmtt89 jmtt89 closed this as completed Jun 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants