start-core/server-functions
Server Functions
Server functions are type-safe RPCs created with createServerFn. They run exclusively on the server but can be called from anywhere — loaders, components, hooks, event handlers, or other server functions.
CRITICAL: Server functions are RPC endpoints. They are reachable by direct POST regardless of which route renders the calling UI. Auth must be enforced inside the handler (or via middleware) — a route
beforeLoaddoes NOT protect the RPC. See start-core/auth-server-primitives for the session/middleware pattern. CRITICAL: Loaders are ISOMORPHIC — they run on BOTH client and server. Database queries, file system access, and secret API keys MUST go insidecreateServerFn, NOT in loaders directly. CRITICAL: Do not use"use server"directives,getServerSideProps, or any Next.js/Remix server patterns. TanStack Start usescreateServerFnexclusively.
Basic Usage
import { createServerFn } from '@tanstack/react-start'
// GET (default)
const getData = createServerFn().handler(async () => {
return { message: 'Hello from server!' }
})