App Router · Server Components
Next.js
Fetch content in a Server Component. The request runs on the server, so your delivery key never reaches the browser. With `revalidate` Next caches the response; with a webhook on publish you refresh precisely instead of on a timer.
- Webhook on publish → a route handler that calls revalidateTag("articles")
- generateStaticParams() with the same call for static detail pages
- Put a preview token in a cookie and serve drafts inside draftMode()
app/blog/page.tsx
const API = process.env.DRYSTONE_API_URL;
async function getArticles() {
const res = await fetch(`${API}/api/v1/content/articles?sort=-published_at&limit=10`, {
headers: { Authorization: `Bearer ${process.env.DRYSTONE_API_KEY}` },
// Time-based revalidation, or keep it and call revalidateTag() from your webhook.
next: { revalidate: 300, tags: ["articles"] },
});
if (!res.ok) throw new Error(`Drystone: HTTP ${res.status}`);
const { data } = await res.json();
return data;
}
export default async function BlogPage() {
const articles = await getArticles();
return (
<ul>
{articles.map((a) => (
<li key={a.id}><a href={`/blog/${a.slug}`}>{a.title}</a></li>
))}
</ul>
);
}