RouterHandler <Context>
Hierarchy
- Router<Context>
- RouterHandler
Callable
Parameters
ctx: Context
Returns Awaitable<void>
Index
Methods
addDefaultHandler
Registers default route handler.
Type parameters
- UserData: Dictionary = GetUserDataFromRequest<Context[request]>
Parameters
handler: (ctx: Omit<Context, request> & { request: Request<UserData> }) => Awaitable<void>
Returns void
addHandler
Registers new route handler for given label.
Type parameters
- UserData: Dictionary = GetUserDataFromRequest<Context[request]>
Parameters
label: string | symbol
handler: (ctx: Omit<Context, request> & { request: Request<UserData> }) => Awaitable<void>
Returns void
getHandler
Returns route handler for given label. If no label is provided, the default request handler will be returned.
Parameters
optionallabel: string | symbol
Returns (ctx: Context) => Awaitable<void>
Returns route handler for given label. If no label is provided, the default request handler will be returned.
Parameters
ctx: Context
Returns Awaitable<void>
use
Registers a middleware that will be fired before the matching route handler. Multiple middlewares can be registered, they will be fired in the same order.
Parameters
middleware: (ctx: Context) => Awaitable<void>
Returns void
Simple router that works based on request labels. This instance can then serve as a
requestHandler
of your crawler.Alternatively we can use the default router instance from crawler object:
For convenience, we can also define the routes right when creating the router:
Middlewares are also supported via the
router.use
method. There can be multiple middlewares for a single router, they will be executed sequentially in the same order as they were registered.