Skip to main content

RegExpRoute

First added

Workbox

About

RegExpRoute makes it easy to create a Route object with a regular expression.

For same-origin requests the RegExp only needs to match part of the URL. For requests against third-party servers, you must define a RegExp that matches the start of the URL.

Parameters

  • regExp — The regular expression to match against URLs.
  • handler — A callback function that returns a Promise resolving to a Response.
  • method — The HTTP method to match the route against. Defaults to GET.

Usage

import { NetworkFirst, RegExpRoute, Serwist } from "serwist";

const serwist = new Serwist();

serwist.registerRoute(new RegExpRoute(/^\/api\/.*/, new NetworkFirst(), "POST"));

serwist.addEventListeners();

More resources

Here is a list of resources you can read to learn more about RegExpRoute: