A full-stack Base44 app: TanStack Start (React 19, plain JavaScript) with file-based routes, server functions and server routes, server-rendered and hosted by Base44.
| Route | File |
|---|---|
/ |
src/routes/index.jsx — a server-rendered page whose loader calls a server function |
GET /api/time |
src/routes/api/time.js — a server route: a raw HTTP endpoint next to the pages |
npm ci
base44 login # one-time per machine
base44 link # one-time per clone
base44 dev # local backend + app togethernpm run build # -> dist/client (assets) + dist/server (the Worker)
base44 deploy # or publish from the Base44 builderThere is no index.html: the HTML document is rendered on the server from src/routes/__root.jsx. The build runs through the Cloudflare Vite plugin, so dev and build both execute server code in workerd.
- Pages are files in
src/routes/. A route'sloaderruns on the server for a document request and in the browser for a client navigation;Route.useLoaderData()gives the component the resolved data. - Server functions (
src/lib/server-fns.js) are RPCs created withcreateServerFn.src/start.jsruns every one of them throughauthMiddleware, which sends the visitor's token along, socontext.getBase44()returns a client acting as that visitor and entity access rules apply.context.getBase44().asServiceRolebypasses them, so use it only after authenticating the caller (.middleware([requireUser])) and checking they may access the records involved: server functions and server routes are public endpoints anyone can call with any input. See Server Security inAGENTS.md. Call it only in handlers that need Base44: it reads the platform headers, and a handler that never calls it works without them. - Secrets are read in server code with
import { secrets } from "base44:runtime"→secrets.get("NAME"), inside a handler. Neverprocess.env. - Server routes (
src/routes/api/*.js) are raw HTTP endpoints for URLs something other than the app's own code requests (webhooks, downloads, feeds); the app's pages call server functions.src/start.jsruns every request throughbase44RequestMiddleware, so theirserver.handlersreceive the samecontext.getBase44()(({ request, params, context }) => …). - Server-only code lives in
*.server.jsfiles (TanStack refuses to bundle them for the browser). - Auth is resolved client-side after hydration (
useAuth()); the server is anonymous on a document request, so give per-user pagesssr: false. - Sign-in and gated pages are not wired in the starter:
src/components/auth/holds the pages (login, register, password reset, MCP consent) and a login gate forsrc/routes/_authed/, to add when the app needs them. See Adding Authentication inAGENTS.md. - AI: TanStack AI is installed and runs on the Base44 AI gateway, with no API key and usage billed to the app's AI credits.
gatewayModel(context.getBase44())insrc/lib/ai.server.jsbuilds the adapter;AGENTS.mdhas a streaming chat example (a server route plususeChat). - Caching: the platform caches only what a route opts into via
headers()(Cache-Control: public, s-maxage=…). Everything else is served fresh.