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, and mark it removed when it is taken down. 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 ({ event, data }) => { // A post tried again can arrive after a newer one, so act only on what changed last. const held = await articles.get(data.id); if (held && held.modifiedAt > data.modifiedAt) return; // A removed article is kept marked removed, not deleted, so an older post arriving late // can't bring it back. Show only the ones not removed. await articles.put(data.id, { ...data, removed: event === 'article.removed' }); },});If your endpoint misses a post
Section titled “If your endpoint misses a post”Every publish, change and take-down is posted, so a site that refreshes on each post stays current with nothing else. If your endpoint is down, the post is tried again. If it never takes it, the site’s owner sees it in Needs you with Try again, and it is sent again once the endpoint is fixed.