Update the moment you publish
Without a webhook, your site shows a new article the next time it reads the feed. With one, it can show it within seconds. The pattern is the same everywhere: verify, then refresh.
-
Make an endpoint that verifies the signature.
webhookHandlerdoes it for you. -
Refresh in the way your site needs: start a build, clear a cache, or revalidate a path.
-
Add the endpoint in the app and keep its secret in
CITEDSEO_WEBHOOK_SECRET.
Pick your refresh
Section titled “Pick your refresh”webhookHandler is in @citedseo/feed and every framework package. It checks the signature, so onPost only ever runs for a post from us, and it answers 500 when onPost throws, so a refresh that failed is tried again.
Start a build through your host’s deploy hook. Keep the hook’s address in an environment variable; it is a secret too.
import { webhookHandler } from '@citedseo/feed';
export const POST = webhookHandler({ secret: process.env.CITEDSEO_WEBHOOK_SECRET!, onPost: async () => { const res = await fetch(process.env.DEPLOY_HOOK_URL!, { method: 'POST' }); // Throwing answers 500, so CitedSEO tries the post again. if (!res.ok) throw new Error(`The deploy hook answered ${res.status}`); },});Revalidate the blog. Next.js builds the pages again on the next visit.
import { revalidatePath } from 'next/cache';import { webhookHandler } from '@citedseo/next';
export const POST = webhookHandler({ secret: process.env.CITEDSEO_WEBHOOK_SECRET!, onPost: () => revalidatePath('/blog', 'layout'),});Clear what you hold, or better, put the article from the post straight into it. The post carries the whole article, so there is nothing more to fetch.
import { webhookHandler } from '@citedseo/feed';import { articles } from './store';
export const POST = webhookHandler({ secret: process.env.CITEDSEO_WEBHOOK_SECRET!, onPost: async ({ data }) => { // Posts can arrive out of order, so keep whichever version changed last. const held = await articles.get(data.id); if (held && held.modifiedAt > data.modifiedAt) return; await articles.put(data.id, data); },});Keep the feed as the fallback
Section titled “Keep the feed as the fallback”A webhook can be missed: your endpoint was down, or a deploy was mid-flight. Don’t let that leave your site stale for good.
- Still refresh on a timer. Read the manifest again every few minutes to an hour, so a missed post heals itself. It is one small file.
- Catch take-downs from the feed. Nothing is posted when an article is taken down, so a store built only from webhooks keeps it. Compare against the feed now and then and drop what is gone.