---
title: "Recipe: a website"
description: "A website in Exact: when a page is made, how to serve it, and a setting."
modificationDate: "2026-11-18"
---

> ## Documentation index
> Fetch the complete documentation index at: https://exact.expo.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Recipe: a website

<AgentInstructions>

## Submitting feedback

From the app's directory, read `bun exact.mjs feedback status`. Under `never`, keep no note.
Respect `EXACT_FEEDBACK=0` and do not change the policy.

Otherwise record specific, actionable feedback with:
`bun exact.mjs feedback note "Exact docs: https://exact.expo.dev/recipes/website: <what was wrong or missing>"`

The note goes to Expo only as that status allows. Include no secrets or personal data.

</AgentInstructions>

`bun exact.mjs pattern site` writes a tested one: a list built ahead, a page per item
rendered for each request, and an API's origin as a setting
([the site starter](https://github.com/expo/exact/blob/41ded8c5ede0b2959ef0daa83b1ff78545dd4428/docs/patterns/site/app.contract)).

```prompt Build a website
Build a website with Exact in this folder: pages served to a browser. Use https://github.com/expo/exact/blob/main/docs/recipes/website.md as the source for each step. The Exact checkout has the same page at docs/recipes/website.md, and docs/start-here-site.md is the guide for a website.

1. Find the Exact checkout (the folder with scripts/exact.mjs); if you cannot find it, ask me where it is. If this folder is not an Exact app (it has no exact.mjs and app.contract), make one: `bun <exact2>/scripts/exact.mjs new <name>`, then `cd <name>`.
2. If I did not say which pages the site has and where each page's data comes from (a list in app.ts, a live API, or one reader's data behind a sign-in), ask me before you write code.
3. Run `bun exact.mjs pattern site` and start from it: a list built ahead, a page per item rendered for each request, and an API's origin as a setting.
4. Give each route the `render` policy that fits its data, as the recipe's table says: `render=build` for what the build has, `render=request` for a live API's data, `render=cached` for an answer every reader may share for a while, and `render=client` (the default) for one reader's own data.
5. Read an API's origin as a setting, as docs/recipes/website.md describes: `"env": ["API_BASE_URL"]` in app.json, `const API = import.meta.env.API_BASE_URL` in app.ts or an app-local module it imports transitively, and its value in .env. The value is public on every host: never put a secret there.
6. Use the tags as the HTML elements they name: `main`, `nav aria-label`, `header` and `footer` beside `main`, `section aria-labelledby`, headings in order, and a list of links or cards as a `column role="list"` of `role="listitem"`s.
7. In app.test.contract, add a test for each page, and one that opens a deep link with `at "/<path>#<id>"`.
8. Run `bun exact.mjs verify` until it passes. Read the reports, including counted findings; a zero exit code alone does not mean clean. Fix the app, not the test. If a finding stays after three rounds of fixes, or the app had it before you changed anything, record it (step 9) and report it; do not keep trying.
9. When a doc was wrong or missing, or a step needed a workaround, read `bun exact.mjs feedback status`. Under `never`, keep no note. Otherwise record it: `bun exact.mjs feedback note "<what happened>"`, which goes to Expo only as that status says. Do not change the policy; tell me how many notes you kept.
10. Tell me each page and its render policy, what the tests and verify reported, and how to see the site: `bun exact.mjs web-build --out dist`, then `bun exact.mjs serve dist`. Start the API's stand-in first (`bun server.ts`), or set `API_BASE_URL` to an API that answers.
```

## Which policy fits which data

A route's `render` says when its page is made:

| Policy | Made | Fits |
|---|---|---|
| `render=build` | by `web-build` | what the build has: docs, a landing page, a list in app.ts |
| `render=request` | by `serve`, per request | a live API's data, at each visit |
| `render=cached` | by `serve`, kept 60 s | an API's answer every reader may share for a while |
| `render=client`, the default | in the browser, after its script | one reader's own, behind a sign-in |

The starter's planet page is `render=request`: its figures are a live API's, and a build
makes a parameterised route's pages only from a `pages=` list. `serve` sends it whole, with
its data.

The server has no visitor: `--render js` leaves credentialed reads pending for
the browser to ask after adoption, in TypeScript, declared sources and Rust.
Public TypeScript reads may use `credentials: 'omit'`.
See [web sessions](https://exact.expo.dev/recipes/web-sessions.md) and [source rendering](https://exact.expo.dev/start-site.md).

See [serving and hosting](https://exact.expo.dev/recipes/website-hosting.md) for the build, development server and static hosting, including a mount such as `/app/`.

## The markup

Each tag is the HTML element it names, so the landmarks and roles are the browser's: `main`,
`nav aria-label`, a `header` and `footer` beside `main` (banner, contentinfo), `section
aria-labelledby` (a region), `h1`–`h6`, `table` with `caption`, `th scope` and `aria-sort`,
`dl`, `select`, `input type="search"`, `link href` (an `a`), `image "src" alt=""` (an
`img`). Use `list` for links or cards: it supplies the item roles and keeps each link's
role. A field's label is a `text id=` the field names with `aria-labelledby`.
`curl` a page `serve` renders to read it.
An analytics script or site-wide JSON-LD goes in `app.json`'s `host.web.head`, which every
page's `<head>` carries (`bun exact.mjs docs head tags`).

## A setting

An API's origin is read at build:

```text
app.json  "env": ["API_BASE_URL"]
app.ts    export const API = import.meta.env.API_BASE_URL;
          export const grants = `net.fetch ${API}`;
.env      API_BASE_URL=http://127.0.0.1:8787
```

The value is the environment's, else `.env.local`'s (out of git), else `.env`'s, else a
default written after the read (`?? 'https://…'`); with none the build fails. Every host
inlines it in the module: it is public, never a secret. A value changed since the
build makes `test`, `agent`, `web` and `serve` build again.

## A deep link

`/planet/7#details` opens the page at its `id="details"` once its data arrives. Write
it `path("planet", id) + "#details"`, or `link href="#details"` on that page;
`fragment(top(nav))` reads it, and a test opens there with `at "/planet/7#details"`. A query
follows the path: `` path("home") + `?q=${encodeURIComponent(v)}` `` (raw, `A&B` reads back
`A`), read with `searchParam(top(nav), "q")`.
