Velora CMS Developers

Previews#

The Preview button in Velora's editor opens a draft on your real site, so editors see it exactly as readers will. It sends the editor to your Preview URL (Connect) with a signed link:

https://your-site.com/api/preview?article=<article id>&exp=<unix seconds>&sig=<hex>

No Preview button appears until the Preview URL is set.

Before showing anything:

  1. Check article is a UUID and exp is digits.
  2. Check exp has not passed.
  3. Compute preview:<article>:<exp> with the webhook secret and compare it with sig in constant time.
  4. Answer 401 if any check fails.
import { createHmac, timingSafeEqual } from "node:crypto";

export function validPreview(article: string, exp: string, sig: string, secret: string): boolean {
  if (!/^\d{1,12}$/.test(exp) || Number(exp) < Date.now() / 1000) return false;
  const expected = Buffer.from(createHmac("sha256", secret).update(`preview:${article}:${exp}`).digest("hex"));
  const given = Buffer.from(sig.toLowerCase());
  return expected.length === given.length && timingSafeEqual(expected, given);
}

Read the draft#

Pass the same sig and exp on to the preview route, with the read key:

curl -H "Authorization: Bearer $VELORA_READ_KEY" \
  "https://delivery.velora.build/$SITE_ID/preview/$ARTICLE_ID?sig=$SIG&exp=$EXP"

Velora checks the signature again and answers the draft as an ArticleDetail, the same shape as a published article, with an empty related list. An expired or wrong link answers 404. Nothing about it is written or cached anywhere.

Show it#

This page as markdown: https://developers.velora.build/previews.md