Integrate BeechCMS with Vue 3
Connect your Vue 3 application (Vite or Vue CLI) to BeechCMS using the Composition API and @beechcms/client.
You are an expert full-stack developer integrating BeechCMS into a Vue 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 Vue, 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 Vue app
Create a new Vue 3 project with TypeScript using the Vite template:
npm create vite@latest my-vue-app -- --template vue-ts
cd my-vue-app3. Install the official client SDK
Install @beechcms/client in your Vue project:
$ pnpm add @beechcms/client4. Declare environment variables
Create a .env.local file in your Vue project root:
VITE_BEECH_API_URL=http://localhost:8789
VITE_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.
5. Initialize the Beech client
Create src/lib/beech.ts to instantiate the browser client with strong TypeScript typing:
// src/lib/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 const beech = createBeechBrowserClient<AppRegistry>({
baseUrl: import.meta.env.VITE_BEECH_API_URL || 'http://localhost:8789',
publishableKey: import.meta.env.VITE_BEECH_PUBLISHABLE_KEY!
})6. Query and render content
Replace the contents of src/App.vue with an idiomatic Composition API component that fetches articles and renders TipTap rich text via renderRichText:
<!-- src/App.vue -->
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { beech, type Article } from './lib/beech'
import { renderRichText } from '@beechcms/client/richtext'
const articles = ref<Article[]>([])
const loading = ref(true)
const error = ref<string | null>(null)
onMounted(async () => {
try {
loading.value = true
const result = await beech
.collection('articles')
.orderBy('created_at', 'desc')
.limit(10)
.list()
if (result.error) {
error.value = result.error.detail || 'Failed to load articles'
} else if (result.data) {
articles.value = result.data.data
}
} catch (err) {
error.value = err instanceof Error ? err.message : 'Network error'
} finally {
loading.value = false
}
})
</script>
<template>
<main class="container">
<h1>BeechCMS + Vue 3</h1>
<div v-if="loading" class="notice">Loading articles...</div>
<div v-else-if="error" class="notice error">Error: {{ error }}</div>
<div v-else-if="articles.length === 0" class="notice">
No articles found. Publish an article in the BeechCMS dashboard!
</div>
<div v-else class="grid">
<article v-for="article in articles" :key="article.id" class="card">
<img v-if="article.cover_image" :src="article.cover_image" :alt="article.title" />
<h2>{{ article.title }}</h2>
<div v-html="renderRichText(article.body)" class="body-content" />
</article>
</div>
</main>
</template>
<style scoped>
.container {
max-width: 800px;
margin: 0 auto;
padding: 2rem;
font-family: sans-serif;
}
.notice {
padding: 1rem 0;
}
.notice.error {
color: #ef4444;
}
.grid {
display: grid;
gap: 1.5rem;
}
.card {
border: 1px solid #e2e8f0;
border-radius: 8px;
padding: 1.25rem;
}
.card img {
max-width: 100%;
border-radius: 4px;
}
</style>7. Start the app
Run the Vite development server:
npm run devOpen http://localhost:5173 in your browser. You will see your BeechCMS articles rendered reactively on screen.
Production requirements
Before deploying to production:
- Configure Seed Permissions: Verify that your Seed has
allowPublicRead: trueenabled in the admin dashboard so public visitors can fetch published content. - Production API URL: Point
VITE_BEECH_API_URLto your production Cloudflare Worker URL (https://api.yourdomain.com). - Production Publishable Key: Set
VITE_BEECH_PUBLISHABLE_KEYto theBEECH_PUBLISHABLE_KEYvalue in the BeechCMS Worker'swrangler.jsoncvars. It is read-only and public by design. - Client Security: Notice that
@beechcms/client/browseris physically read-only. Mutation methods (create,update,delete) are omitted from browser bundles to keep administrative credentials secure.
Cloudflare Edge Deployment
When deploying your Vue 3 SPA to Cloudflare Pages:
- Zero-Cost Static Hosting: Run
npm run buildto compile into static assets (dist/). In Cloudflare Pages, connect your repository with build commandnpm run buildand output directorydistto host your application on Cloudflare's global edge network at zero compute cost. - SPA History Mode Routing (
_redirects): To support HTML5 History Mode without 404 errors when visitors refresh deep URLs, create apublic/_redirectsfile:text/* /index.html 200 - CORS Configuration: Add your Pages URL (e.g.
https://my-vue-app.pages.dev) toCORS_ORIGINSin your BeechCMS Cloudflare Worker bindings.
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.