MCPcopy
hub / github.com/TanStack/router / handlerToMiddleware

Function handlerToMiddleware

packages/start-server-core/src/createStartHandler.ts:307–321  ·  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

305 * Wrap a route handler as middleware
306 */
307function handlerToMiddleware(
308 handler: RouteMethodHandlerFn<any, AnyRoute, any, any, any, any, any>,
309 mayDefer: boolean = false,
310): TODO {
311 if (mayDefer) {
312 return handler
313 }
314 return async (ctx: TODO) => {
315 const response = await handler({ ...ctx, next: throwIfMayNotDefer })
316 if (!response) {
317 throwRouteHandlerError()
318 }
319 return response
320 }
321}
322
323/**
324 * 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