Preview
The preview is the site’s pages at the addresses /preview (the home page) and /preview/<page> (/preview/menu for /menu). The @seamlet/astro integration adds it; you do not write it yourself.
| Request | What it shows |
|---|---|
GET /preview |
the page with the published content |
POST /preview with the content as JSON |
the page with that content, saving nothing (up to 1 MB) |
This is how the editor sends the draft after every edit, and the site renders the page anew with its own code.
In the editor’s frame the page stands still: the site’s animations and transitions end at once, and scrolling to a field is not smoothed. Otherwise the editor would draw an outline round a field still sliding into its place. An element that appears through an animation from no opacity is shown at once. Visitors see the site’s motion as usual. @seamlet/astro works this way from version 2.10.0.
Beside it the integration adds three more addresses, rendered on request:
/seamlet/site.json— what the site tells the CMS about itself: the id and title fromseamlet.json, the schema, the initial content and the pages. The CMS takes it from the same origin as the preview every time it opens the site in the editor./seamlet-photos/<address>— a photo from the site’s own files by its address in the content, for the CMS’s editor./media/<site>/<file>— photos uploaded to the CMS.
Protection
Section titled “Protection”- Only your CMS may frame the preview:
Content-Security-Policy: frame-ancestors <CMS address>. - Search engines do not index it (
X-Robots-Tag: noindex), browsers do not cache it. - A draft is accepted only as
application/json: a form on another site cannot send it. - The bridge to the editor loads only on
/previewand only inside the CMS’s frame. Visitors of the public pages do not get it.
Where to host it
Section titled “Where to host it”The preview is the site itself, rendering pages on request with the adapter it is deployed with. The address for the CMS is https://<site>/preview. The integration’s routes are rendered on request with any adapter, and the site’s own pages may stay static.
- Vercel —
npx astro add vercel, then deploy the site. The preview runs as a function of the deployment, and its answers carry their own protective headers. - Netlify —
npx astro add netlify, then deploy the site. - A server of your own —
npx astro add node; the site is started withnode dist/server/entry.mjs. - A static site on an ordinary hosting — the CMS builds and serves the preview itself: it takes the server part of the site from its GitHub repository and serves it at
https://<id>.preview.seamlet.ru/preview. The site needs an adapter (@astrojs/node) andseamlet.jsonat the root of the repository. Only the CMS’s administrator connects a site this way.
The address of the CMS is written into the build — from cms in seamlet.json, or from CMS_ORIGIN if the build sets it. The preview does not read it on every request, so after a change of the CMS the site must be built again.
The check of the pages’ texts runs at build time with @astrojs/node only. With another adapter the build skips it and says so.
Connect it to the CMS
Section titled “Connect it to the CMS”The site serves its preview itself. In the CMS: Подключить сайт (Connect a site) → Адрес предпросмотра главной страницы (Preview address of the home page) → https://<site>/preview → Подключить (Connect). The address must start with https:// (http:// only for localhost). The editor opens the other pages under it by itself. A connected site’s address is changed in its Настройки (Settings).
For a developer, the CMS connects only a site with their token in seamlet.json (ownerToken, how to add it). Without the token, or with another account’s, the CMS refuses: «В seamlet.json сайта нет вашего токена» (The site’s seamlet.json does not have your token). The site’s id (id) must be free. For a taken one the CMS answers «Это имя сайта занято» (This site name is taken) — give the site another id in seamlet.json and deploy it again.
The CMS builds the preview — for an administrator only. In the CMS: Подключить сайт (Connect a site) → Предпросмотр собирает CMS (The CMS builds the preview) → the repository, the branch and a fine-grained GitHub token with Contents: Read → Собрать и подключить (Build and connect). The CMS takes the site’s id and title from the branch’s seamlet.json, builds the site and connects it once the build succeeds. When the site’s code changes in the branch, the CMS rebuilds the preview by itself: it looks at the branch every two minutes, so new code reaches the editor within a few minutes. The preview is also built at every deployment by the CMS’s builder, while a publication alone does not rebuild it: the preview shows the published content and the drafts anyway. The copies of the content the CMS puts into the seamlet/ folder do not start a rebuild. To rebuild by hand, press Собрать заново (Build again) in the «Предпросмотр» (Preview) section of the site’s settings; there too is Собрать предпросмотр (Build the preview) for a site already connected that does not serve its own preview.
While the CMS serves the preview, it does not know where the site itself lives. An administrator or the site’s developer gives its address: the site’s Настройки (Settings) → «Адрес сайта» (Site address). «Открыть сайт» (Open the site) in the list of sites and in the editor leads there; without the address the site has no such link.
Without a preview, content is edited in the «Поля» (Fields) panel, without a view of the page.
Versions
Section titled “Versions”The bridge tells the editor the version of its protocol. @seamlet/astro 2.6.0 speaks version 3. The editor understands bridges of its version and older, and asks an old bridge only for what it can do: so a site on 2.5.0 is edited as before, and prices with spaces, time typed on the page, Tab between fields and the grey outline of the site’s own text appear once the site updates the package.
The order of updates: the CMS first, then the sites — whenever they like. If the site’s @seamlet/astro is newer than the CMS understands, the editor shows «Редактору нужно обновление» (“The editor needs an update”) instead of the page. Content can still be edited in the «Поля» (Fields) panel.