Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

server.ts

23 lines681 Bytes

1import handler from '@tanstack/react-start/server-entry'
2import type { ServerRequest } from 'srvx'
3​
4export default {
5 fetch(request: Request) {
6 // Cast to ServerRequest to access Node.js runtime
7 const serverRequest = request as ServerRequest
8​
9 return handler.fetch(request, {
10 responseLinkHeader: true,
11 onEarlyHints: ({ allLinks, phase }) => {
12 if (phase !== 'dynamic') return
13​
14 // Access native Node.js response via srvx's runtime context
15 const nodeRes = serverRequest.runtime?.node?.res
16​
17 if (nodeRes?.writeEarlyHints && allLinks.length) {
18 nodeRes.writeEarlyHints({ link: allLinks })
19 }
20 },
21 })
22 },