setDefaultHandler.mjs 851 B

12345678910111213141516171819202122232425262728
  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.mjs';
  8. import './_version.mjs';
  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 {workbox.routing.Route~handlerCallback} handler A callback
  17. * function that returns a Promise resulting in a Response.
  18. *
  19. * @alias workbox.routing.setDefaultHandler
  20. */
  21. export const setDefaultHandler = (handler) => {
  22. const defaultRouter = getOrCreateDefaultRouter();
  23. defaultRouter.setDefaultHandler(handler);
  24. };