- each method throws ForumApiError with the status and message - createThread and editPost answers, moderation 422 under title or body - non-JSON, empty and malformed error bodies; empty success bodies
vue-forum-layer
A Nuxt layer with the member forum of the SummerCMS forum plugin: categories, threads and Markdown posts of one forum context, rendered from the server's sanitized HTML.
export default defineNuxtConfig({ extends: ['vue-forum-layer'] })
Overview
golem15.forum answers a JSON API under /_forum/api/v1, behind the user's frontend JWT. Every route lives under /contexts/{type}/{id}: the host application registers its forum contexts and decides, through its access policy, who reads, posts and manages in each one. The layer renders one context:
<ForumPage>: the categories, the selected category's threads and a "new thread" editor;<ForumThread>: one thread's posts, a reply editor, Edit and Delete on the user's own posts (and on every post for a moderator).
Posts are written in Markdown. The server renders and sanitizes them on write and answers content_html, which is the only HTML the layer binds. The editor's Preview button calls the server's POST /contexts/{type}/{id}/preview; the layer never renders Markdown itself. Titles and names render as text.
Installation
Add the layer as a git dependency pinned to a tag, next to the Nuxt and Vue versions it is built for:
{
"dependencies": {
"nuxt": "4.4.8",
"vue": "3.5.35",
"vue-forum-layer": "git+https://git.golem15.com/golem15/vue-forum-layer.git#v0.1.0"
}
}
The layer declares @nuxtjs/i18n (10.4.0), so the app does not list it again. It registers its forum.* copy only for the locales the app enables (en, pl). The browser calls the forum API on the site's own origin: route /_forum to the application (a dev proxy locally, the web server in production).
Runtime config
| Key | Env | Default | Purpose |
|---|---|---|---|
forum.apiBase |
NUXT_FORUM_API_BASE |
http://127.0.0.1:8096/_forum/api/v1 |
Server-only forum API base, for an app page that fetches forum data on the server |
public.forum.apiBase |
NUXT_PUBLIC_FORUM_API_BASE |
/_forum/api/v1 |
Browser base of golem15.forum |
Usage
The components fetch with the user's token from the browser, so render them on the client only. The app owns the routes, passes the context and builds thread URLs:
<!-- pages/forum/index.vue -->
<template>
<ClientOnly v-if="loggedIn">
<ForumPage context-type="acme" :context-id="1" :thread-path="(id) => `/forum/t/${id}`" />
</ClientOnly>
<NuxtLink v-else to="/register">Register to join the forum</NuxtLink>
</template>
<!-- pages/forum/t/[id].vue -->
<template>
<ClientOnly v-if="loggedIn">
<ForumThread context-type="acme" :context-id="1" :thread-id="String(route.params.id)" back-path="/forum" :can-manage="isModerator" />
</ClientOnly>
</template>
Components
| Component | Props | Purpose |
|---|---|---|
ForumPage |
contextType, contextId, threadPath(id) |
Categories, threads of the selected category, new thread; a created thread opens at threadPath |
ForumThread |
contextType, contextId, threadId, canManage?, backPath? |
Posts, reply, edit and delete; marks the thread read on open; emits deleted |
ForumCategoryList |
categories, selected |
The category list; emits select |
ForumThreadList |
threads, meta, threadPath(id) |
One page of threads; emits page |
ForumPostEditor |
submit, preview?, withTitle?, initialTitle?, initialBody?, submitLabel?, cancellable? |
Markdown textarea with the server preview; shows 422 field errors |
The forum API does not report moderator rights. A host that knows its moderators passes canManage to ForumThread, which then shows Edit and Delete on every post and Delete thread. The server decides either way: an action it refuses hides itself for the session.
The auth hook
The app provides forumAuth from a Nuxt plugin, a function answering the user's frontend JWT, or null:
// plugins/forum-auth.ts
export default defineNuxtPlugin(() => ({
provide: { forumAuth: () => readTokenCookie() },
}))
Every request carries Authorization: Bearer {token}, never a cookie. The layer never stores the token.
API reference
createForumClient({ base, token, fetch? })(app/utils/forumClient.ts):categories,threads(ctx, categoryId?, page?),posts(ctx, threadId, page?),createThread,reply,editPost,deletePost,deleteThread,markRead,unreadandpreview, each taking the context{ type, id }first. Refusals throwForumApiErrorwithstatus,messageanderrors(field(name)gives the first message of a field).forumContextPath(ctx)andforumError(status, json)are exported for tests and hosts.useForumApi(): the client bound to runtime config and$forumAuth;useForumAuth(): the hook.useForum(context): categories, the selected category, its threads, the open thread and its posts, with the actions the components use.
Styling
app/assets/css/forum-base.css uses --forum-* variables with defaults (font, colors, radius, gap). Set them in the app's css to restyle the forum, or replace a component with a same-name file. Class names carry the forum- prefix.
Testing
pnpm install
pnpm test # node --test: every client method's URL, body and refusal, the Bearer header, the 422 and error-body mapping
pnpm build:playground # builds .playground against the layer