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

Function executeRouter

packages/start-server-core/src/createStartHandler.ts:544–614  ·  view source on GitHub ↗
(
        serverContext: TODO,
        matchedRoutes?: ReadonlyArray<AnyRoute>,
      )

Source from the content-addressed store, hash-verified

542
543 // Router execution function
544 const executeRouter = async (
545 serverContext: TODO,
546 matchedRoutes?: ReadonlyArray<AnyRoute>,
547 ): Promise<SsrResponse> => {
548 const acceptHeader = request.headers.get('Accept') || '*/*'
549 const acceptParts = acceptHeader.split(',')
550 const supportedMimeTypes = ['*/*', 'text/html']
551
552 const isSupported = supportedMimeTypes.some((mimeType) =>
553 acceptParts.some((part) => part.trim().startsWith(mimeType)),
554 )
555
556 if (!isSupported) {
557 return normalizeSsrResponse(
558 Response.json(
559 { error: 'Only HTML requests are supported here' },
560 { status: 500 },
561 ),
562 )
563 }
564
565 const manifest = await resolveManifestForRequest({
566 request,
567 requestInlineCss: requestOpts?.inlineCss,
568 getBaseManifest: () => getBaseManifest(matchedRoutes),
569 })
570
571 const earlyHints = createEarlyHintsForRequest({
572 onEarlyHints: requestOpts?.onEarlyHints,
573 responseLinkHeader: requestOpts?.responseLinkHeader,
574 })
575
576 earlyHints?.collectStatic({ manifest, matchedRoutes })
577
578 const routerInstance = await getRouter()
579
580 attachRouterServerSsrUtils({
581 router: routerInstance,
582 manifest,
583 getRequestAssets: () =>
584 getStartContext({ throwIfNotFound: false })?.requestAssets,
585 })
586
587 // `additionalContext` is request-scoped and only read from router.options
588 // during load; avoid a full router.update() and redundant location parse.
589 routerInstance.options.additionalContext = { serverContext }
590 await routerInstance.load()
591
592 if (routerInstance.state.redirect) {
593 return normalizeSsrResponse(routerInstance.state.redirect)
594 }
595
596 earlyHints?.collectDynamic(routerInstance.stores.matches.get())
597
598 // Pass request-scoped assets to dehydrate for manifest injection
599 const ctx = getStartContext({ throwIfNotFound: false })
600 await routerInstance.serverSsr!.dehydrate({
601 requestAssets: ctx?.requestAssets,

Callers 1

handleServerRoutesFunction · 0.85

Calls 8

getStartContextFunction · 0.90
normalizeSsrResponseFunction · 0.85
getStartResponseHeadersFunction · 0.85
getRouterFunction · 0.70
getMethod · 0.65
jsonMethod · 0.65
loadMethod · 0.65

Tested by

no test coverage detected