File size: 900 Bytes
d711d0a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | import { createServerFn } from "@tanstack/react-start";
import { z } from "zod";
import { getServerConfig } from "../config.server";
// Example createServerFn. Server-side handler invoked from the client:
// const result = await getGreeting({ data: { name: "Ada" } })
// The .handler body runs server-only — imports used only inside it (like
// .server.ts modules) are tree-shaken from the client bundle. Module-level
// code here still ships to the client; for truly server-only helpers, put
// them in a .server.ts file. Use this pattern instead of Supabase Edge
// Functions for server logic.
export const getGreeting = createServerFn({ method: "POST" })
.inputValidator(z.object({ name: z.string().min(1) }))
.handler(async ({ data }) => {
const config = getServerConfig();
return {
greeting: `Hello, ${data.name}!`,
mode: config.nodeEnv ?? "unknown",
};
});
|