Frameworks

Other Frameworks

Connect Tenon to any server that speaks Request and Response. Vite-based frameworks get the smoothest setup.

Tenon works with any server that can hand a web Request to a function and send back its Response. You route the API, serve the admin page and register the types yourself. Vite apps get the admin build from tenonAdmin().

Before you start

You need:

  • A server runtime, like Node, Bun or Deno. The admin and the API are server routes, so a static host cannot run them.
  • tenon.config.ts at the project root. See Configuration.

Route the API

Send every request for /_tenon/*, /sitemap.xml and /robots.txt to cms.fetch(request). Pass every method, not only GET and POST:

server.ts
import cms from "./tenon.config";

const seoPaths = ["/sitemap.xml", "/robots.txt"];

export default {
  fetch(request: Request) {
    const { pathname } = new URL(request.url);
    if (pathname.startsWith("/_tenon/") || seoPaths.includes(pathname)) {
      return cms.fetch(request);
    }
    // The routes of your own app go here.
    return new Response("Not found", { status: 404 });
  },
};

Leave out /sitemap.xml or /robots.txt when your app serves them itself. See Sitemap and robots.txt.

Serve the admin

The admin is a page at admin.path, /admin by default. Serve it for that path and every path below it.

Add tenonAdmin() to the Vite config. It builds the admin and exposes its page as #tenon/admin-html:

vite.config.ts
import { tenonAdmin } from "tenoncms/vite";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [tenonAdmin()],
});

Return the page from your server. cms.adminPath holds admin.path:

server.ts
import html from "#tenon/admin-html";
import cms from "./tenon.config";

const admin = cms.adminPath!;

export default {
  fetch(request: Request) {
    const { pathname } = new URL(request.url);
    if (pathname === admin || pathname.startsWith(`${admin}/`)) {
      return new Response(html, { headers: { "content-type": "text/html; charset=utf-8" } });
    }
    return cms.fetch(request);
  },
};

tenonAdmin() throws when the config sets admin: false. Its options are on the TanStack Start page.

To ship no admin at all, set admin: false in tenon.config.ts. The API keeps working. See Without the admin.

Read content and preview

Server code imports the instance from tenon.config.ts. For pages, read as the user of the request, so editors see drafts in the preview:

const tenon = await cms.withSession(request);
const posts = await tenon.find("posts");

On the pages, start the live preview once in the browser. Any bundler builds tenoncms/preview:

src/site.ts
import { preview } from "tenoncms/preview";

preview({ admin: "/admin" });
  • Mark what a field renders with edit(). In Vue and React, useDraft() from tenoncms/preview/vue or tenoncms/preview/react merges unsaved changes. See Live preview.
  • Without a Tenon Vite plugin, the admin bar skips items with browser code from clientRef(). Links and menus still show.
  • The components of tenoncms/vue and tenoncms/react work in any app. See Components.

Types and jobs

Register the types of your CMS in tsconfig.json:

tsconfig.json
{
  "compilerOptions": {
    "types": ["tenoncms/register"],
    "paths": { "#tenon/config": ["./tenon.config.ts"] }
  }
}

This types createClient() from tenoncms/client without a type argument, and #tenon/admin-html with Vite.

Due jobs run only when something calls cms.jobs.run(). tenonAdmin() runs them every minute when the app builds with Nitro. Otherwise, call cms.jobs.run() every minute yourself, or call the clock route from a cron service. See The clock.