Skip to content
Source
Sign inSign up
TanStack/router

Docs: Clarify server entry point can be extended with Cloudflare queue/scheduled handlers #6487

Send to my agent
Closedalexander-zuev(GitHub profile, opens in a new tab) opened this issue 2 comments

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:

  1. The pattern above
  2. That createServerEntry() returns a spreadable object
  3. 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
  1. go ahead and create a PR for the docs

  2. schiller-manuel(GitHub profile, opens in a new tab) added labelsdocumentation

  3. @schiller-manuel raised a PR to clarify this in docs - lmk if aligns with the doc standards or I should change wording in any way

Sign in to join this conversation.