-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
documentationEverything documentation relatedEverything documentation related
Description
Documentation Gap
The Server Entry Point docs explain that createServerEntry() returns a ServerEntry with a fetch handler, but don't mention that this can be extended with additional Cloudflare Workers handlers.
What We Discovered
createServerEntry() returns a plain object:
export function createServerEntry(entry: ServerEntry): ServerEntry {
return {
async fetch(...args) {
return await entry.fetch(...args)
},
}
}This means you can spread it and add queue, scheduled, and other handlers:
import handler, { createServerEntry } from '@tanstack/react-start/server-entry'
// Durable Objects work as named exports
export { MyDurableObject } from './my-do'
const serverEntry = createServerEntry({
async fetch(request) {
return await handler.fetch(request)
},
})
// Combine all handlers in one export
export default {
...serverEntry,
async queue(batch, env, ctx) {
// Process queue messages
for (const message of batch.messages) {
console.log('Processing:', message.body)
message.ack()
}
},
async scheduled(event, env, ctx) {
// Handle cron triggers
console.log('Cron triggered:', event.cron)
},
}Why This Matters
This allows TanStack Start to be used as a complete Cloudflare Worker entrypoint with:
- SSR + server functions (fetch)
- Queue consumers
- Cron/scheduled handlers
- Durable Objects (named exports)
All in one file, one worker, one deployment.
Suggested Documentation Addition
Add a section to the Server Entry Point docs titled "Extending with Cloudflare Workers Handlers" showing:
- The pattern above
- That
createServerEntry()returns a spreadable object - How to test locally:
- Queue: works automatically
- Scheduled:
curl "http://localhost:5173/cdn-cgi/handler/scheduled?cron=*+*+*+*+*"
Environment
- TanStack Start with
@cloudflare/vite-plugin - Cloudflare Workers
- Tested and working in production
Metadata
Metadata
Assignees
Labels
documentationEverything documentation relatedEverything documentation related