MCPcopy Create free account
hub / github.com/TanStack/router / handlerToMiddleware

Function handlerToMiddleware

packages/start-server-core/src/createStartHandler.ts:417–431  ·  view source on GitHub ↗

* Wrap a route handler as middleware

(
  handler: RouteMethodHandlerFn<any, AnyRoute, any, any, any, any, any>,
  mayDefer: boolean = false,
)

Source from the content-addressed store, hash-verified

415 * Wrap a route handler as middleware
416 */
417function handlerToMiddleware(
418 handler: RouteMethodHandlerFn<any, AnyRoute, any, any, any, any, any>,
419 mayDefer: boolean = false,
420): TODO {
421 if (mayDefer) {
422 return handler
423 }
424 return async (ctx: TODO) => {
425 const response = await handler({ ...ctx, next: throwIfMayNotDefer })
426 if (!response) {
427 throwRouteHandlerError()
428 }
429 return response
430 }
431}
432
433/**
434 * Creates the TanStack Start request handler.

Callers 1

handleServerRoutesFunction · 0.85

Calls 2

throwRouteHandlerErrorFunction · 0.85
handlerFunction · 0.50

Tested by

no test coverage detected