Configuration
This page explains the one file every Tenon project has, and what Tenon adds to your app. For every option, see the configuration reference.
tenon.config.ts
tenon.config.ts sits in the root of your project. It default-exports one CMS instance, made by defineCms(). Everything Tenon knows comes from this file: your content types, the database, users, media and the admin.
Three things read it:
- Your pages import the instance to read content, like
cms.find("posts"). - The framework integration serves the API and the admin from it.
- The
tenonCLI loads it for backups, users and upgrades.
defineCms() checks the config when it loads. If something is missing or invalid, the server stops at startup with an error. See Startup checks.
The smallest config
Only database and secret are required:
import { defineCms } from "tenoncms";
import { sqlite } from "tenoncms/sqlite";
export default defineCms({
database: sqlite("./cms.db"),
secret: process.env.TENON_SECRET!,
});
database: where content and users are stored.sqlite()uses Node's built-in SQLite, so there is nothing to install. Tenon createscms.dbon the first request. For other databases, see Databases.secret: signs sessions and tokens. It needs at least 32 characters.
This already gives you a working admin, users, a media library in ./.uploads and the Settings page. It has no content types yet.
Add a collection right in the config:
import { defineCms } from "tenoncms";
import { sqlite } from "tenoncms/sqlite";
export default defineCms({
database: sqlite("./cms.db"),
secret: process.env.TENON_SECRET!,
collections: {
posts: {
fields: {
title: { type: "text", required: true },
},
},
},
});
The key posts is the name you pass to find("posts"). The starters move each collection into its own file in collections/ with defineCollection(). See Collections and globals.
Environment variables
Tenon reads no environment variable at runtime. tenon.config.ts passes every value, so you decide where it comes from. The starters use these names:
| Variable | Required | What it is |
|---|---|---|
TENON_SECRET | Yes | The value of secret. Generate one with openssl rand -hex 32. |
TENON_SITE_URL | No | The value of site.url, the public origin. Set it in production only. |
Each framework loads them in its own way:
Declare the variables in the env schema of astro.config.ts, and import them from astro:env/server. Astro checks them at startup.
import { defineConfig, envField } from "astro/config";
export default defineConfig({
env: {
schema: {
TENON_SECRET: envField.string({ context: "server", access: "secret", min: 32 }),
TENON_SITE_URL: envField.string({
context: "server",
access: "secret",
url: true,
optional: true,
}),
},
},
});
import { TENON_SECRET, TENON_SITE_URL } from "astro:env/server";
export default defineCms({
secret: TENON_SECRET,
site: { url: TENON_SITE_URL, name: "My Site" },
// ...
});
Declare each value in runtimeConfig, and read it with useRuntimeConfig() in tenon.config.ts. Nuxt fills each key from a variable with the NUXT_ prefix: tenonSecret reads NUXT_TENON_SECRET.
export default defineNuxtConfig({
modules: ["tenoncms/nuxt"],
runtimeConfig: {
tenonSecret: "",
tenonSiteUrl: "",
},
});
const config = useRuntimeConfig();
export default defineCms({
secret: config.tenonSecret,
site: { url: config.tenonSiteUrl || undefined, name: "My Site" },
// ...
});
Read the variables from process.env in tenon.config.ts.
export default defineCms({
secret: process.env.TENON_SECRET!,
site: { url: process.env.TENON_SITE_URL, name: "My Site" },
// ...
});
In development, the dev server loads .env. In production, npm start loads it with Node's --env-file-if-exists=.env, or you set the variables on the host.
Site URL
site.url is the public origin of your site, like https://example.com. It has no path. The sitemap, robots.txt, preview links, sign-in and links into the admin use it.
Leave it unset in development. Tenon then uses the origin of each request, so localhost works on any port. Set it in production.
site.name is the name the admin, emails and passkeys show.
auth.baseURL to the CMS origin. See Authentication.Variables of the CLI
The tenon CLI reads two more, to work against a deployed site instead of the local config:
TENON_URL: the URL of the deployed site.TENON_API_KEY: an API key for that site.
See the CLI.
How Vite fits in
Tenon runs inside your app. tenon.config.ts is a normal module: a server route imports it, and your app's Vite build compiles it like any other file.
- Astro and Nuxt: the integration adds the routes and the admin for you.
- TanStack Start and other Vite frameworks:
tenonAdmin()fromtenoncms/vitebuilds the admin, and you write the route files.
How Tenon works explains what happens under the hood.
Routes Tenon adds
| Route | Serves |
|---|---|
/_tenon/* | The HTTP API: content, media files, sign-in, users and the admin's data. |
/admin | The admin. Change the path with admin.path, or turn it off with admin: false. |
/sitemap.xml | Every published document of each collection with a permalink. Turn it off with sitemap: false. |
/robots.txt | Allows the site except /_tenon, and points to the sitemap. Turn it off with robots: false. |
Astro and Nuxt add all four. If your app already serves /sitemap.xml or /robots.txt, Tenon leaves that route to your app. On TanStack Start, each route is a file in src/routes/, and the sitemap and robots.txt need one more file each. See TanStack Start.
Every API route is listed in the HTTP routes reference.