question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What is the signature for a custom route handler?

See original GitHub issue

Library Affected: https://developers.google.com/web/tools/workbox/modules/workbox-routing#matching_and_handling_in_routes

Issue or Feature Request Description: The handler callback method in the docs has the following signature:

const handlerCb = ({url, event, params})

But the handle method in all of the workbox strategies seems to have the following signature;

async handle({ event, request }) 

I see from the debugger that the object passed to the handle method has the following properties:

{
   url: URL, 
   request: Request, 
   event: FetchEvent, 
   params: undefined
}

Could these docs be updated? Or could they point to the API docs for Workbox? (Sorry. I am a java programmer struggling to adjust to this crazy javascript stuff.)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
philipwaltoncommented, Apr 6, 2020

But the handle method in all of the workbox strategies seems to have the following signature;

async handle({ event, request }) 

@daffinm note that, in JavaScript, you generally only list the parameters a given method is using—not all the parameters it’s invoked with.

In the case of Workbox strategies, they all only use the request and event params, but since Workbox’s routing interface accepts handlers that may also use url and/or params, every invocation of a handler function (which all strategy classes handle() method is) from a Router object needs to be invoked with all four object params, even if the function doesn’t end up using them.

1reaction
jeffposnickcommented, Apr 6, 2020

The relevant TypeScript definitions are at https://github.com/GoogleChrome/workbox/blob/3ac095656354157eb4b58c93d3b1e390a5ba34dd/packages/workbox-core/src/types.ts#L36-L56

Ultimately, that’s the intended “source of truth”.

I’m not sure which docs you were looking at, but if anything doesn’t match that (which is unfortunately possible; our docs are generated from JSDocs, not the TypeScript signature) then it’s an issue with the docs that we’ll resolve.

https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-routing#~handlerCallback is the “official” docs—is that what you were looking at? If not, what’s the URL of the page?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Route handlers - Mirage JS
Route handlers let you define which URLs your Mirage server can handle. The simplest route handler maps a URL ... Each verb method...
Read more >
Using a Custom RouteHandler in MVC 2 - Blog
So I was trying to use a custom RouteHandler in ASP. ... the MapRoute() method doesn't have a signature to provide a custom...
Read more >
Routing - Laravel - The PHP Framework For Web Artisans
Underscores ( _ ) are also acceptable within route parameter names. Route parameters are injected into route callbacks / controllers based on their...
Read more >
Working with routes for WebSocket APIs - Amazon API Gateway
API Gateway calls a custom route after the route selection expression is evaluated against the message if a matching route is found; the...
Read more >
HOW TO MAKE YOUR OWN CUSTOM ROUTES IN ...
This is where we would assign a custom route for your application. ... To register events, Umbraco exposes the ApplicationEventHandler base class.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found