Stay fresh
Every read is cached, so pages are fast and the polis site isn't asked for anything twice. Three things make it new again, each for a different reason.
1. Publishing: the webhook. Your polis site POSTs a signed event to your website whenever a post is
published, updated or removed. polisWebhook checks the signature, answers straight away, then expires just
that post's page and the post list:
// The publish webhook. vdibart.polis.pub POSTs here, signed, whenever a post
// is published, updated or removed ("all posts from me"). polisWebhook checks
// the signature, answers at once, then expires the cached reads of that post
// and of the post list, so the next reader gets the new pages.
import { polisWebhook } from '@polis-pub/next';
export const POST = polisWebhook({ secret: process.env.POLIS_WEBHOOK_SECRET ?? '' });To subscribe it, in your polis site's owner app open Enhance → Webhooks → Add a webhook, choose
When: you post, and send it to https://<your website>/polis-webhook. Or tell your agent "notify my website
when I post". The secret appears once: put it in POLIS_WEBHOOK_SECRET and redeploy. Then press the
webhook's test ping: "Sent a signed ping: it answered" means the address and the secret are both right, since
the route refuses anything it can't verify.
2. Changing the design: just deploy. A design change is a code change, and every deployment renders every
page again from the current code. You never need to publish something to see a new design. Locally,
npm run dev reloads as you edit.
3. Re-reading everything, on demand. For a fresh start, a webhook that was down, or plain curiosity,
polisRefresh expires every cached read at once. It's closed until you give it a secret:
// Re-read everything from the polis site, on demand, with no post:
// curl -X POST -H "Authorization: Bearer $POLIS_REFRESH_SECRET" https://vdibart.com/polis/refresh
// Closed (404) unless POLIS_REFRESH_SECRET is set. A design change needs none
// of this: every deployment renders every page from the current code.
import { polisRefresh } from '@polis-pub/next';
export const POST = polisRefresh({ secret: process.env.POLIS_REFRESH_SECRET });Make the secret yourself, and set it where the site runs (Vercel's environment variables, or .env.local):
openssl rand -hex 32 # → POLIS_REFRESH_SECRET, marked Sensitive in Vercel; then redeploy
Then, whenever you want:
curl -X POST -H "Authorization: Bearer $POLIS_REFRESH_SECRET" https://vdibart.com/polis/refresh
| Answer | Means |
|---|---|
200 {"refreshed":true} |
done: the next request for each page renders from fresh files |
401 |
the secret doesn't match the one this deployment has |
404 |
POLIS_REFRESH_SECRET isn't set on this deployment |
Keep the secret out of the repository and out of browser code.