Drafts and previews
How your client sees unpublished edits on your real website, and what your code needs to do for it.
Open with AI
Your client’s edits are drafts until they publish. A preview shows those drafts on your actual website, with your real layout, before anything goes live.
How a preview reaches your page
Section titled “How a preview reaches your page”-
Your client clicks Preview in the dashboard.
-
AtMyApp opens your website with a preview key in the URL:
?amaPreviewKey=…. The key is signed, scoped to that editing session, and expires on its own. -
Your page reads the key from the request and passes it to the SDK.
-
Every read made with that key returns the drafts layered over the published content.
That means previews need a page that renders per request. A static HTML file built yesterday can’t show today’s draft. The usual setup is a static production site plus a dynamic preview server.
AtMyApp preview servers
Section titled “AtMyApp preview servers”Under Settings → Dev servers, AtMyApp can run your repository’s dev server for previews. Each preview gets its own address, such as https://p-…-preview.atmyapp.com. The preview proxy keeps amaPreviewKey in the URL while your client clicks around the site, including client-side navigation, so links between pages keep showing drafts.
With @atmyapp/astro this needs no code: preview servers run Astro in dynamic mode, and getAtMyApp(Astro) picks up the key from each request. See Astro modes and previews.
Previews in your own code
Section titled “Previews in your own code”With @atmyapp/core, create a client for each request, with the key from that request:
import { createAtMyAppClient } from "@atmyapp/core";import schema from "../atmyapp.schema";
export function amaForRequest(url: URL) { const previewKey = url.searchParams.get("amaPreviewKey") ?? undefined; return createAtMyAppClient({ baseUrl: process.env.ATMYAPP_API_URL!, apiKey: process.env.ATMYAPP_API_KEY!, schema, previewKey, mode: previewKey ? "priority" : "client", errorPolicy: "throw", });}You can also pass the key to a single read: ama.storage.getValue("home", { previewKey }).
- One client per request. A preview key stored in a shared, module-level client would leak drafts to every visitor.
- Never cache preview responses publicly. AtMyApp marks preview responses
no-store; keep it that way in your CDN. - Fail loudly. If a preview key is invalid or expired, show an error. Falling back to published content would make your client think their edit is live.
- Keep the key in links if you run your own preview host. AtMyApp’s preview proxy does this for you; elsewhere, add
amaPreviewKeyto internal links or store it in a session.
What else changes in a preview
Section titled “What else changes in a preview”The SDKs adjust a few behaviours when a preview key is present:
| In a preview | |
|---|---|
| Search engines | AtMyAppHead adds noindex, nofollow. |
| Forms | AtMyAppForm is disabled unless you add allowPreviewSubmit. Submissions that do get through are labelled preview and kept out of the inbox. |
| Analytics | Page views are not tracked. |
| Collections | Lists include draft entries. A few complex queries (OR filters, very large collections) may not match publishing exactly; the SDK warns when that happens. |
Publishing
Section titled “Publishing”When your client publishes, drafts become the published content. Static sites on AtMyApp hosting rebuild automatically; other setups refresh as described in How AtMyApp works.
