Integrate BeechCMS with Nuxt 3
Deliver blazing fast SSR and universal hydration by pairing BeechCMS with Nuxt 3 and @beechcms/client.
You are an expert full-stack developer integrating BeechCMS into a Nuxt application.
BeechCMS is an edge-native headless CMS built on Cloudflare Workers, D1, and R2.
Documentation Base: https://fdemusso.github.io/BeechCMS/
Official Client SDK: @beechcms/client
Forms SDK: @beechcms/forms-react
Search Client: @beechcms/search-client
Key Architecture Guidelines:
- Edge Native: Sub-millisecond latency on Cloudflare edge.
- Client SDK: Use createBeechBrowserClient / createBeechServerClient from '@beechcms/client/browser' or '@beechcms/client/server' with baseUrl and publishableKey (browser) or secretKey (server).
- Content Querying: Every read starts at beech.collection('seedSlug') and returns a fluent query builder. Chain .where({ field: value }) or .where({ field: { gte: 10 } }), .logic('AND' | 'OR'), .orderBy('created_at', 'desc'), .search(term), .select([...]), .include([...]), .limit(n), .page(n), then terminate with .list() or .first(). Example: beech.collection('seedSlug').orderBy('created_at', 'desc').limit(10).list(), or beech.collection('seedSlug').where({ slug }).first().
- Relations: .include(['author']) expands related entries in the same request under entry._includes.author (depth 1, max 3 branches). .whereRelation('author', { where: { name: 'Jane' } }) filters through the relation target server-side. Never issue N+1 follow-up requests.
- Result Unwrapping: Extract records from result.data.data and handle errors via result.error. .first() returns a 404 BeechProblem when nothing matches — it does not return null.
- Types: Generate the seed registry with 'npx beech types generate' and pass it as the client generic: createBeechBrowserClient<BeechDatabase>({ ... }).
- RichText: Render TipTap body AST via renderRichText(post.body) from '@beechcms/client/richtext'.
- Content Models: Seeds define schemas, Branches define fields, Fruits represent content items.
- Dual-Table Mirror Staging: Drafts stay isolated in draft staging tables and promote atomically to production.
Generate the integration code following strict TypeScript typing, clean error handling, and modern edge-rendering patterns.1. Set up your BeechCMS backend & sample Seed
Before querying data in Nuxt, ensure you have a running BeechCMS instance with sample content:
- Start BeechCMS: If running locally, start your backend via
pnpm run dev(running onhttp://localhost:8789), or use your deployed Cloudflare Worker URL. - Verify or Create the Seed: In your BeechCMS admin dashboard (
/admin), verify you have anarticlesSeed with:- Branches:
title(Text) andbody(Rich Text). Do not add aslugbranch:slugis a reserved system column that BeechCMS fills from the title on every entry (hello-beechcms); theslugfield used below is that column. - Permissions: Ensure Allow Public Read (
allowPublicRead) is checked so public requests can fetch content without admin secrets.
- Branches:
- Publish a Fruit (Record): Create at least one article and click Publish.
2. Create a Nuxt app
Create a new Nuxt 3 project using the official CLI:
npx nuxi@latest init my-nuxt-app
cd my-nuxt-app3. Install the official client SDK
Install @beechcms/client in your Nuxt project:
$ pnpm add @beechcms/client4. Declare environment variables
Add your configuration in nuxt.config.ts:
// nuxt.config.ts
export default defineNuxtConfig({
runtimeConfig: {
public: {
beechApiUrl: process.env.BEECH_API_URL || 'http://localhost:8789',
beechPublishableKey: process.env.BEECH_PUBLISHABLE_KEY
}
}
})Create a .env file in your Nuxt project root:
BEECH_API_URL=http://localhost:8789
BEECH_PUBLISHABLE_KEY=beech_pk_dev
beech_pk_devis the publishable key every new project has inwrangler.jsonc. It is read-only and safe in the bundle.runtimeConfig.publicis shipped to the browser, so it must never hold the secret key.
5. Initialize the Beech client plugin
Create a Nuxt plugin in plugins/beech.ts to provide the typed browser client to the universal Nuxt context:
// plugins/beech.ts
import { createBeechBrowserClient } from '@beechcms/client/browser'
export interface Article {
id: string
title: string
slug: string
cover_image?: string
body: string | Record<string, unknown>
created_at: number
updated_at: number
}
export interface AppRegistry {
articles: Article
}
export default defineNuxtPlugin(() => {
const config = useRuntimeConfig()
const client = createBeechBrowserClient<AppRegistry>({
baseUrl: config.public.beechApiUrl,
publishableKey: config.public.beechPublishableKey!
})
return {
provide: {
beech: client
}
}
})6. Query and render content
Replace app.vue (or pages/index.vue if using the pages directory) with a universal component utilizing useAsyncData and renderRichText:
<!-- app.vue -->
<script setup lang="ts">
import { renderRichText } from '@beechcms/client/richtext'
const { $beech } = useNuxtApp()
const { data: articles, pending, error } = await useAsyncData('articles', async () => {
const result = await $beech
.collection('articles')
.orderBy('created_at', 'desc')
.limit(10)
.list()
return result.data ? result.data.data : []
})
</script>
<template>
<main style="max-width: 800px; margin: 0 auto; padding: 2rem; font-family: sans-serif;">
<h1>BeechCMS + Nuxt 3</h1>
<div v-if="pending">Loading articles...</div>
<div v-else-if="error" style="color: #ef4444;">Failed to load articles.</div>
<div v-else-if="!articles || articles.length === 0">
No articles found. Publish an article in the BeechCMS dashboard!
</div>
<div v-else style="display: grid; gap: 1.5rem;">
<article
v-for="article in articles"
:key="article.id"
style="border: 1px solid #e2e8f0; border-radius: 8px; padding: 1.25rem;"
>
<img
v-if="article.cover_image"
:src="article.cover_image"
:alt="article.title"
style="max-width: 100%; border-radius: 4px;"
/>
<h2 style="margin-top: 0.5rem;">{{ article.title }}</h2>
<div v-html="renderRichText(article.body)" />
</article>
</div>
</main>
</template>7. Start the app
Run the Nuxt development server:
npm run devOpen http://localhost:3000 in your browser. You will see your BeechCMS articles hydrated universally on screen.
Production requirements
Before deploying to production:
- Configure Seed Permissions: Ensure your Seed has
allowPublicRead: trueenabled in the admin dashboard so public visitors can fetch published content. - Production API URL: Point
BEECH_API_URLto your production Cloudflare Worker URL (https://api.yourdomain.com). - Production Publishable Key: Set
BEECH_PUBLISHABLE_KEYto theBEECH_PUBLISHABLE_KEYvalue in the BeechCMS Worker'swrangler.jsoncvars. It is read-only and public by design. - Hydration & SSR:
useAsyncDataserializes payloads during server-side rendering and avoids duplicate requests during client hydration.
Cloudflare Edge Deployment
When deploying Nuxt 3 to Cloudflare Pages:
- Built-in Nitro Preset: Nuxt includes native Cloudflare support via Nitro with zero additional packages. Set the build preset:bash
NITRO_PRESET=cloudflare-pages npm run build - Node.js Compatibility: Ensure
compatibility_flags = ["nodejs_compat"]is enabled in your Cloudflare Pages project settings. - Edge Caching via
routeRules: Cache rendered BeechCMS content directly at Cloudflare's edge with stale-while-revalidate behavior:typescript// nuxt.config.ts export default defineNuxtConfig({ routeRules: { '/articles/**': { isr: 60 } // Cache at the edge for 60 seconds } })
Next steps
- 5-Minute First Project Tutorial: Follow a step-by-step tutorial covering project scaffolding, database bootstrap, visual modeling, and deployment.
- Client SDK Reference: Explore advanced querying, filtering, and pagination parameters.
- Public API Reference: Understand Edge REST endpoints, caching headers, and RFC 7807 error responses.
- Forms SDK (@beechcms/forms-react): Capture user submissions and feedback with zero secrets and built-in bot defense.