1import { createFileRoute } from "@tanstack/react-router";
2import { createServerFn } from "@tanstack/react-start";
3import { Card } from "../components/Card.tsx";
4import { env } from "../env.ts";
5
6// Runs on the server for both the SSR render and client navigations — in
7// the deployed Worker (or, under `alchemy dev`, in TanStack Start's own
8// Vite dev server). The `env` declared on the Website in alchemy.run.ts
9// is available through the `cloudflare:workers` env proxy.
10const getGreeting = createServerFn({ method: "GET" }).handler(
11 () => env.GREETING ?? "Hello!",
12);
13
14export const Route = createFileRoute("/")({
15 loader: () => getGreeting(),
16 component: Home,
17});
18
19function Home() {
20 const greeting = Route.useLoaderData();
21 return (
22 <main>
23 <h1 className="text-3xl font-bold">{greeting}</h1>
24 <Card
25 title="Styled with Tailwind CSS"
26 body="This card is a React component styled with Tailwind utilities."
27 />
28 </main>
29 );
30}