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

Function handlerToMiddleware

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

329 * Wrap a route handler as middleware
330 */
331function handlerToMiddleware(
332 handler: RouteMethodHandlerFn<any, AnyRoute, any, any, any, any, any>,
333 mayDefer: boolean = false,
334): TODO {
335 if (mayDefer) {
336 return handler
337 }
338 return async (ctx: TODO) => {
339 const response = await handler({ ...ctx, next: throwIfMayNotDefer })
340 if (!response) {
341 throwRouteHandlerError()
342 }
343 return response
344 }
345}
346
347/**
348 * 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