Skip to content

Instant publishing

By default each SDK refreshes on its own clock (Next’s ISR revalidate, an Astro rebuild). To make a just-published article appear in seconds, subscribe to the feed.updated webhook: when the engine rebuilds your site’s static feed it POSTs a small signed body to your registered URL, and your app revalidates on the spot.

Read Instant updates for the concept; this page is the per-framework wiring.

The body is JSON:

{ "event": "feed.updated", "siteId": "your-site-id", "buildId": "..." }

The request carries three headers — Webhook-Id, Webhook-Timestamp, and Webhook-Signature (v1=<hex>, an HMAC-SHA256 over the id, timestamp, and raw request body, keyed by a shared secret you set when you register the subscription). Always verify that signature over the raw bytes before you act on the request, or anyone who learns your URL can force-revalidate your cache. Signing the id and timestamp together makes it replay-safe, and the stable Webhook-Id lets you dedupe a retried delivery.

@ghostwritr/next/revalidate ships a ready-made route handler. It verifies the signature, then busts the cache tags (and any paths you list):

app/api/revalidate/route.ts
import { createRevalidateHandler } from "@ghostwritr/next/revalidate";
export const POST = createRevalidateHandler({
secret: process.env.GHOSTWRITR_FEED_SECRET!,
tags: ["ghostwritr"], // default; matches createGhostwritr({ tags })
paths: ["/blog"], // optional: revalidate concrete paths too
});

For tag-based revalidation to take effect, your data client must tag its fetches. Set the same tag on the client:

lib/ghostwritr.ts
import "server-only";
import { createGhostwritr } from "@ghostwritr/next/server";
export const gw = createGhostwritr({
siteId: process.env.GHOSTWRITR_SITE_ID!,
tags: ["ghostwritr"], // on-demand revalidation target
});

Register https://your-site.com/api/revalidate as the webhook URL. The full reference is Instant revalidation.

  • The concept — what the webhook fires on and the manifest re-fetch it triggers. See Instant updates.
  • The signing helperssignWebhook / verifyWebhook and the WEBHOOK_* header constants. See Webhook helpers.
  • Build a blog — the end-to-end guide this fits into. See Build a blog.