setDefaultHandler.js 864 B

1234567891011121314151617181920212223242526
  1. /*
  2. Copyright 2019 Google LLC
  3. Use of this source code is governed by an MIT-style
  4. license that can be found in the LICENSE file or at
  5. https://opensource.org/licenses/MIT.
  6. */
  7. import { getOrCreateDefaultRouter } from './utils/getOrCreateDefaultRouter.js';
  8. import './_version.js';
  9. /**
  10. * Define a default `handler` that's called when no routes explicitly
  11. * match the incoming request.
  12. *
  13. * Without a default handler, unmatched requests will go against the
  14. * network as if there were no service worker present.
  15. *
  16. * @param {module:workbox-routing~handlerCallback} handler A callback
  17. * function that returns a Promise resulting in a Response.
  18. *
  19. * @memberof module:workbox-routing
  20. */
  21. function setDefaultHandler(handler) {
  22. const defaultRouter = getOrCreateDefaultRouter();
  23. defaultRouter.setDefaultHandler(handler);
  24. }
  25. export { setDefaultHandler };