Forum: a service of its own and the /forum pages

services/forum (axum, port 8083) on the same database and login, in the
forum schema (migration 0038, which also adds the moderator role):
nicknames, profiles with shared signs, topics, threads with listening or
advice intent, two-level replies, read marks and followed threads,
reactions as ratings with points and ranks, newcomer limits (lifted by a
purchase), moderation with reasons, bans and a log. Integration tests run
in CI.

The frontend's /forum pages (light by default, dark on request, phone
first with a desktop layout) are switched on by FORUM_URL; the /api/v1
proxy sends /api/v1/forum/* to the forum service. Concept and status:
docs/kozosseg.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-26 10:29:49 +00:00
co-authored by Claude Opus 5.5
parent fa46dcb757
commit 36b38525c3
52 changed files with 6782 additions and 11 deletions
+29
View File
@@ -0,0 +1,29 @@
// Forum service calls from server components, with the visitor's session.
// Without FORUM_URL the forum is switched off (no menu item, its pages 404).
import "server-only";
import { cookies } from "next/headers";
import { BackendError, SESSION_COOKIE } from "./server";
export const FORUM_URL = (process.env.FORUM_URL ?? "").replace(/\/$/, "");
export function forumEnabled(): boolean {
return FORUM_URL !== "";
}
/** The answer of a forum GET: the data, or why there is none. */
export type ForumResult<T> = { ok: true; data: T } | { ok: false; status: 401 | 404 };
/** GET from the forum service as the visitor (logged in or not). */
export async function forumGet<T>(path: string): Promise<ForumResult<T>> {
if (!forumEnabled()) return { ok: false, status: 404 };
const token = (await cookies()).get(SESSION_COOKIE)?.value;
const headers: HeadersInit = token ? { authorization: `Bearer ${token}` } : {};
const res = await fetch(`${FORUM_URL}${path}`, { headers, cache: "no-store" });
if (res.status === 401 || res.status === 404) return { ok: false, status: res.status };
// Not allowed (e.g. the moderation log for a member): the page does not exist for them.
if (res.status === 403) return { ok: false, status: 404 };
if (!res.ok) throw new BackendError(res.status, `${path}: HTTP ${res.status}`);
return { ok: true, data: (await res.json()) as T };
}