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