Headless CMS for Next.js
Fetch in a server component, so the key stays on the server and pages can be static. Every item of a page with many items gets its own route, with a 404 when it doesn't exist.
- Revalidate on a timer: each release clears the API's cache at once.
- An old item address answers with its new slug, so redirects are easy.
import { notFound } from "next/navigation" // A server component: the key never reaches the browser.export default async function Service({ params }) { const { slug } = await params const res = await fetch(`${process.env.MYWEBCMS_API_URL}/pages/services/${slug}`, { headers: { Authorization: `Bearer ${process.env.MYWEBCMS_API_KEY}` }, next: { revalidate: 60 }, }) if (res.status === 404) notFound() const { data } = await res.json() return <h1>{data.title}</h1>}