Other Frameworks
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.tsat 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:
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:
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:
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.
Serve a page with an empty element, and mount the admin into it with a script that your bundler builds:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="robots" content="noindex, nofollow" />
<title>Admin</title>
<script type="module" src="/admin.js"></script>
</head>
<body>
<div id="admin"></div>
</body>
</html>
import { mountAdmin } from "tenoncms/admin/mount";
mountAdmin("#admin", "/admin");
The second argument is admin.path. It defaults to /admin.
Browser modules (.client.ts) need a Tenon Vite plugin. Without Vite, name your admin code with clientRef(), and pass the list of modules to mountAdmin() yourself. Each key is the exact string of a clientRef() call:
import { mountAdmin } from "tenoncms/admin/mount";
mountAdmin("#admin", "/admin", null, {
"./src/admin/color.ts#mountColor": () => import("./admin/color").then((m) => m.mountColor),
});
The third argument is the URL of a favicon, or null.
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:
import { preview } from "tenoncms/preview";
preview({ admin: "/admin" });
- Mark what a field renders with
edit(). In Vue and React,useDraft()fromtenoncms/preview/vueortenoncms/preview/reactmerges 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/vueandtenoncms/reactwork in any app. See Components.
Types and jobs
Register the types of your CMS in 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.
Related resources
- How Tenon works: the routes, the admin and the CLI, and how Vite fits in.
- Standalone: the same pieces in a project with no pages.
- TanStack Start: a full Vite setup with route files.
- HTTP routes: every route of the API.