Serving Inngest on TanStack Start

This is a quick snippet on how to serve Inngest on TanStack Start. Up-to-date as of 14th June 2025. Ensure you're using the latest version of TanStack Start with server routes.

// src/routes/api/inngest

import { inngest, functions } from "~/inngest"; // Your inngest client and functions array.

import { createServerFileRoute } from "@tanstack/react-start/server";
import { InngestCommHandler, type ServeHandlerOptions } from "inngest";

const serve = (options: ServeHandlerOptions) => {
  const handler = new InngestCommHandler({
    frameworkName: "TanStack Start",
    fetch: fetch.bind(globalThis),
    ...options,
    handler: ({ request }: { request: Request }) => {
      return {
        body: () => request.json(),
        headers: (key) => request.headers.get(key),
        method: () => request.method,
        url: () =>
          new URL(request.url, `https://${request.headers.get("host") || ""}`),
        transformResponse: ({ body, status, headers }) => {
          return new Response(body, { status, headers });
        },
      };
    },
  });

  return handler.createHandler();
};

const handler = serve({ client: inngest, functions });

export const ServerRoute = createServerFileRoute("/api/inngest").methods({
  GET: handler,
  POST: handler,
  PUT: handler,
});