Skip to content

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

@alexander-zuev

Description

@alexander-zuev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationEverything documentation related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions