Add a visual page editor to a Next.js application

6 min read · Updated 2026-09-12

Short answer

How do you add a visual page editor to a Next.js app?

Install the pagiera package, point it at PostgreSQL and Redis, mount its catch-all API route under /api/pagiera, load the editor bootstrap on the server, and render the studio behind your own authentication. The editor runs inside your application rather than on a separate hosted account, so the pages it produces are rendered by your own Next.js server.

Key points

  1. 01Pagiera is an npm package, not a hosted editor account — it runs inside your own Next.js app.
  2. 02PostgreSQL stores documents and revisions; Redis caches published pages, template bundles and AI rate limits.
  3. 03One catch-all route handler at /api/pagiera/[...path] serves the whole editor backend.
  4. 04The editor route is yours to protect: Pagiera does not ship an authentication layer.

Steps

  1. 01

    Install the package

    Pagiera ships the editor, the runtime and the server handlers in a single package. Node.js 20+, React 18.3+ and the Next.js App Router are required for the full-stack integration.

    bash
    bun add pagiera
  2. 02

    Configure the services

    Create .env.local with a PostgreSQL connection and a Redis connection. An OpenRouter key is only needed if you want AI generation; everything else works without it.

    env
    PAGIERA_POSTGRES_URL=postgresql://postgres:postgres@localhost:5432/pagiera
    PAGIERA_REDIS_URL=redis://localhost:6379
    OPENROUTER_API_KEY=sk-or-v1-your-key
    OPENROUTER_MODEL=anthropic/claude-sonnet-4.5

    Pagiera creates the PostgreSQL tables it needs when the server first initializes. You do not run a separate migration step.

  3. 03

    Mount the backend

    A single catch-all route handler exposes every editor endpoint. Export the verbs it returns and Next.js routes the rest.

    ts
    // src/app/api/pagiera/[...path]/route.ts
    import {
      createPagieraRouteHandlers,
      pagieraConfigFromEnv,
    } from "pagiera/server";
    
    export const maxDuration = 120;
    export const dynamic = "force-dynamic";
    
    const handlers = createPagieraRouteHandlers(pagieraConfigFromEnv());
    export const { GET, POST, PUT, PATCH, DELETE } = handlers;

    Open /api/pagiera/health after starting the app. It reports whether PostgreSQL, Redis and the configured OpenRouter model are reachable, which turns a silent misconfiguration into a readable answer.

  4. 04

    Load the editor data on the server

    The first document is server-rendered, so the studio opens with content instead of a loading state.

    ts
    // src/lib/editor-bootstrap.ts
    import {
      getPagieraServer,
      pagieraConfigFromEnv,
    } from "pagiera/server";
    
    export async function editorBootstrap(pageId?: string) {
      const server = await getPagieraServer(pagieraConfigFromEnv());
      const bootstrap = await server.getEditorBootstrap(pageId);
    
      if (!bootstrap) throw new Error("Editor page not found");
      return bootstrap;
    }
  5. 05

    Mount the studio behind your own auth

    Render the studio on a route only your team can reach. Pagiera deliberately does not ship an authentication layer — the editor route and the API route inherit whatever your application already enforces.

    • Protect both the editor page and /api/pagiera with the same check.
    • Import the editor stylesheet before your own CSS: @import rules must precede other rules.
    • Add the font provider so next/font families appear in the Typography panel.

What each service is responsible for

ServiceWhat it holds
PostgreSQLPage documents, drafts and published revisions — the durable source of truth.
RedisPublished-page cache, template bundle cache and AI rate limiting.
OpenRouterOptional. Only used when you ask the AI panel to propose a change.

Questions

  1. 01Pagiera as a CMSUse Pagiera as a self-hosted CMS for a Next.js site
  2. 02API data bindingBind API data to a visually designed page

Say hi to Pagiera and build your first page

Install the package and have the studio running in minutes.

bun add pagiera