Skip to main content
HydroGo
REST APIDraft previews

Draft previews

Show unpublished pages and articles in your own frontend with signed, short-lived preview links.

Editors often need to see a draft inside the real site before they publish. HydroGo issues revision-bound, signed preview tokens; your frontend uses them to fetch the draft.

How it works

  • An editor asks the admin for a preview link: POST /api/v1/admin/pages/{id}/preview-link.
  • The response contains a signed token bound to that revision.
  • Your frontend calls GET /api/v1/pages/{id}/preview?token=<token> (news has the matching /api/v1/news/{id}/preview) from the server side and renders the draft.
  • Responses carry Cache-Control: private, no-store, so previews are never cached by a CDN.
TS
// SvelteKit: src/routes/preview/[id]/+page.server.ts
import { env } from '$env/dynamic/private';
import { error } from '@sveltejs/kit';

export async function load({ params, url }) {
  const token = url.searchParams.get('token');
  if (!token) error(400, 'Missing preview token');
  const res = await fetch(
    `${env.HYDRO_API_ORIGIN}/api/v1/pages/${params.id}/preview?token=${encodeURIComponent(token)}`,
  );
  if (!res.ok) error(res.status, 'Preview unavailable');
  const { data } = await res.json();
  return { page: data };
}
Set security.preview_signing_key (at least 32 bytes, or HYDRO_PREVIEW_SIGNING_KEY) in production so preview links survive restarts and cannot be forged. Do not index preview routes: serve them with X-Robots-Tag: noindex.
API keys with the preview scope are the other way to read unpublished content from a trusted server.