mirror of
https://github.com/TanStack/router.git
synced 2026-11-16 19:38:07 +00:00
1.6 KiB
1.6 KiB
| id | title |
|---|---|
| server-entry-point | Server Entry Point |
Server Entry Point
Note
The server entry point is optional out of the box. If not provided, TanStack Start will automatically handle the server entry point for you using the below as a default.
This is done via the src/server.ts file.
// src/server.ts
import handler from '@tanstack/react-start/server-entry'
export default {
fetch(request: Request) {
return handler.fetch(request)
},
}
The entry point must conform to the following interface:
export default {
fetch(req: Request): Promise<Response> {
// ...
},
}
Whether we are statically generating our app or serving it dynamically, the server.ts file is the entry point for doing all SSR-related work.
Custom Server Handlers
You can create custom server handlers to modify how your application is rendered:
// src/server.ts
import {
createStartHandler,
defaultStreamHandler,
} from '@tanstack/react-start/server'
// Custom handler example
const customHandler = (request, response) => {
// Add custom logic here
return defaultStreamHandler(request, response)
}
const fetch = createStartHandler(customHandler)
export default {
fetch,
}
Server Configuration
The server entry point is where you can configure server-specific behavior:
- Request/response middleware
- Custom error handling
- Authentication logic
- Database connections
- Logging and monitoring
This flexibility allows you to customize how your TanStack Start application handles server-side rendering while maintaining the framework's conventions.