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

Function createStartHandler

packages/start-server-core/src/createStartHandler.ts:377–679  ·  view source on GitHub ↗
(
  cbOrOptions: HandlerCallback<AnyRouter> | CreateStartHandlerOptions,
)

Source from the content-addressed store, hash-verified

375 * ```
376 */
377export function createStartHandler<TRegister = Register>(
378 cbOrOptions: HandlerCallback<AnyRouter> | CreateStartHandlerOptions,
379): RequestHandler<TRegister> {
380 const handlerOptions: FinalManifestOptions =
381 typeof cbOrOptions === 'function' ? {} : cbOrOptions
382 const cb: HandlerCallback<AnyRouter> =
383 typeof cbOrOptions === 'function' ? cbOrOptions : cbOrOptions.handler
384 const finalManifestResolver = createFinalManifestResolver({
385 ...handlerOptions,
386 cacheCreateTransform: process.env.TSS_DEV_SERVER !== 'true',
387 })
388 const resolveManifestForRequest =
389 process.env.TSS_DEV_SERVER === 'true'
390 ? finalManifestResolver.resolveUncached
391 : finalManifestResolver.resolveCached
392
393 if (process.env.TSS_DEV_SERVER !== 'true') {
394 finalManifestResolver.warmup({
395 getBaseManifest: () => getBaseManifest(undefined),
396 })
397 }
398
399 const startRequestResolver: RequestHandler<Register> = async (
400 request,
401 requestOpts,
402 ) => {
403 let router: AnyRouter | null = null as AnyRouter | null
404 let responseOwnsCleanup = false as boolean
405
406 try {
407 // normalizing and sanitizing the pathname here for server, so we always deal with the same format during SSR.
408 // during normalization paths like '//posts' are flattened to '/posts'.
409 // in these cases we would prefer to redirect to the new path
410 const { url, handledProtocolRelativeURL } = getNormalizedURL(request.url)
411 const href = url.pathname + url.search + url.hash
412 const origin = getOrigin(request)
413
414 if (handledProtocolRelativeURL) {
415 return Response.redirect(url, 308)
416 }
417
418 const entries = await getEntries()
419 const hasStartInstance = !!entries.startEntry.startInstance
420 const startOptions: AnyStartInstanceOptions =
421 (await entries.startEntry.startInstance?.getOptions()) ||
422 ({} as AnyStartInstanceOptions)
423
424 const { hasPluginAdapters, pluginSerializationAdapters } =
425 entries.pluginAdapters
426
427 const serializationAdapters = [
428 ...(startOptions.serializationAdapters || []),
429 ...(hasPluginAdapters ? pluginSerializationAdapters : []),
430 ServerFunctionSerializationAdapter,
431 ]
432
433 const requestStartOptions = {
434 ...startOptions,

Callers 10

server.tsFile · 0.90
server.tsFile · 0.90
server.tsFile · 0.90
server.tsFile · 0.90
server.tsFile · 0.90
server.tsFile · 0.90
server.tsFile · 0.90
server.tsFile · 0.90
server.tsFile · 0.90

Calls 2

requestHandlerFunction · 0.90

Tested by

no test coverage detected