@webroute/middlewareType aliases
ToFrameworkHandlers
ToFrameworkHandlers<
T
,TResult
>: (...args
) =>object
A set of mutually exclusive handlers called depending on the middleware return type.
Only one of the functions will be called for each request.
Type Parameters
Type Parameter | Default type |
---|---|
T extends AnyFrameworkMiddlewareFn | AnyFrameworkMiddlewareFn |
TResult extends AnyMiddlewareResult | AnyMiddlewareResult |
Parameters
Parameter | Type |
---|---|
...args | Parameters <T > |
Returns
object
Name | Type | Description |
---|---|---|
onData | (data ) => Awaitable <ReturnType <T >> | Called when data is returned from the middleware. Example req.field = data.field next() // Next should be called, if necessary |
onEmpty | () => Awaitable <ReturnType <T >> | Called when nothing was returned. Example // Continuing app execution. next()`` |
onError | (error ) => Awaitable <ReturnType <T >> | Called when the middleware throws an error. Example // Throw the error throw error; |
onResponse | (response ) => Awaitable <ReturnType <T >> | Called when a response is returned from the middleware. Example // Pass to next app function... next(response) // ...or return it return response // ...or send response res.json(await response.json()) |
onResponseHandler | (handler ) => Awaitable <ReturnType <T >> | Called when a response handler is returned from the middleware. Example // Get the response... const response = await next() // ...then pass to handler return handler(response) |