Configuration
defineCms() takes one object. Only database and secret are required. Each entry below links to the page that explains the option in depth. For what tenon.config.ts is and how Tenon reads it, see Configuration.
import { defineCms } from "tenoncms";
import { sqlite } from "tenoncms/sqlite";
export default defineCms({
database: sqlite("./cms.db"),
secret: process.env.TENON_SECRET!,
collections: {
// ...
},
});
Content
collections
Record<string, Collection>. Default: {}.
The collections, keyed by name. The name media is reserved for the media library. See Collections and globals.
globals
Record<string, Global>. Default: {}.
The globals, keyed by name. While their settings are on, general, seo and translations are taken. See Collections and globals.
blocks
Record<string, Block>. Default: {}.
Shared blocks. A blocks field names them by key instead of defining them. A block MAY name itself, so items nest to any depth.
presets
Preset[]. Default: [].
Ready-made collections, globals and blocks, like pagesPreset(), menuPreset() and stringsPreset() from tenoncms/presets. They merge after your own entries and before the plugins. A duplicate name throws. See Presets.
settings
SettingsOptions | false. Default: general and seo.
The globals on the admin's Settings page. false removes all of them. See Settings.
Global replaces it, false removes it.noindex. A Global replaces it, false removes it.localization when a localized entry has list fields. It holds one switch per entry for keeping the structure of lists the same in every language. false removes it.Without media, general has no favicon and seo has no image. With localization, both are localized.
localization
LocalizationOptions. Default: off.
Content in several languages. Without it, a localized option throws at startup. See Localization.
locale, and the target of the fallback. MUST be one of locales.true.false leaves routing to your app. Default: { prefix: "except-default" }.populate
PopulateOptions. Default: {}.
Defaults for reads that resolve relations. See Relations.
populate: true resolves. It also sets the depth of the result types. Default: 2.5. depth MUST NOT be larger.Server
database
DatabaseOptions. Required.
The database. Create it with an adapter:
| Adapter | Import | Database |
|---|---|---|
sqlite() | tenoncms/sqlite | A SQLite file, with node:sqlite |
libsql() | tenoncms/libsql | libSQL and Turso |
postgres() | tenoncms/postgres | Postgres |
pglite() | tenoncms/pglite | PGlite |
durableObject() | tenoncms/cloudflare | SQLite in a Durable Object |
A missing URL or path fails at startup. See Databases.
secret
string. Required.
Signs sessions. It MUST have at least 32 characters, also in development. Read it from an environment variable. See Configuration.
site
SiteOptions. Default: none.
https://example.com. The sitemap, robots.txt and preview URLs use it. It is also the default of auth.baseURL and of the CORS origin. MUST be an http(s) origin without a path. Default: the origin of each request."tenoncms".See Configuration and Branding.
auth
AuthOptions. Default: {}.
The options of better-auth, passed through. Tenon sets database, secret and basePath (/_tenon/auth) itself, and the models user, session, account and verification MUST NOT set modelName. See Authentication.
Tenon changes these defaults:
| Key | Default in Tenon |
|---|---|
baseURL | site.url, then better-auth's environment variables, then localhost in development |
appName | site.name |
emailAndPassword.enabled | true |
emailAndPassword.sendResetPassword, emailVerification.sendVerificationEmail | The templates of email, when it is set |
rateLimit.storage | "database" |
user.additionalFields | Also has language and timezone |
plugins | Tenon adds admin(), apiKey(), bearer() and a few of its own, unless you add them |
The first user always gets the role admin. At least one sign-in method MUST be on.
roles
Record<string, RoleOptions>. Default: only admin and editor.
More roles for access rules. A name MUST use a-z, 0-9 and -, and MUST NOT be admin or editor.
email
EmailOptions. Default: off. Without it, cms.email.send() throws. See Email.
smtp(), cloudflareEmail() or a custom adapter.My Site <hello@example.com>.resetPassword, verifyEmail, invite, signInLink, magicLink and emailOtp. See Change the built-in emails.media
MediaOptions | boolean. Default: local files in .uploads.
The media library, and with it image and file fields. false turns it off. On Cloudflare Workers, or in a read-only folder, the default is off and true throws. See Media.
local(), s3(), r2() from tenoncms/media/*, or your own. See Media storage.100 * 1024 ** 2 (100 MB).image/* works. Default: all.Responsive image variants. Default: false. See Responsive images.
| Key | Type | Default |
|---|---|---|
provider | ImageProvider, required | |
format | string | "webp" |
quality | number | 85 |
sizes | number[] | [320, 640, 1024, 1536, 1920] |
presets | Record<string, Modifiers> | {} |
maxSize | number, in bytes | 50 MB. Bigger images get no variants |
read also guards the file and image URLs. Default: everyone reads, signed-in users write.beforeUpload, afterUpload, beforeChange, afterChange, beforeMove, afterMove, beforeDelete and afterDelete.cors
CorsOptions. Default: off.
CORS for pages on another origin, with the options of Hono's cors(). Your keys replace the defaults key by key: origin is site.url, credentials is true, allowMethods is ["GET", "POST"] and allowHeaders is ["content-type"]. It covers the read, preview, localization and admin bar routes. It needs origin or site.url. See Headless.
Site output
sitemap
SitemapOptions | false. Default: on.
Serves /sitemap.xml with the published documents of every collection that has a permalink. entries: ({ cms, entries }) => entries adds, drops or changes entries. false turns it off. See Sitemap and robots.txt.
robots
RobotsOptions | false. Default: on.
Serves /robots.txt. By default it allows / and /_tenon/media/, disallows /_tenon/, and links the sitemap. With the SEO setting noindex, it disallows /. rules: ({ cms, rules }) => rules changes the groups. false turns it off.
Automation
jobs
JobsOptions. Default: none. See Jobs.
defineTask(), by name. A name MUST NOT start with tenon:.Authorization: Bearer <secret>. Without it, the route does not exist.webhooks
Record<string, Webhook>. Default: {}.
Outgoing webhooks, by name: url, collections, globals, events, payload, debounce, secret and headers. See Send webhooks.
hooks
RootHooks. Default: {}.
Hooks for every collection and global. They run after the hooks of the entry and of the plugins. See Hooks.
Lifecycle
All four take one function. See Lifecycle hooks.
| Option | Runs |
|---|---|
seed | Once, on a database without documents and globals |
onInit | On every start, after seed, before the first request |
afterImport | After cms.import() commits |
afterError | After an unexpected error in a request, a job, seed or onInit |
Admin and plugins
admin
AdminOptions | false. Default: the admin at /admin.
false serves no admin, no admin bar and no device login for the CLI. See Admin.
- and _. MUST NOT be / or start with /_tenon. Default: "/admin".icon, then the favicon of your site, then Tenon's icon.custom:<key> fields. See Custom fields."bottom-center". See Admin bar.richtext
{ extensions?: Record<string, RichtextRegistration> }. Default: {}.
Tiptap extensions for richtext fields, keyed by the name that a field's allowed lists. Each has a schema for the server and a client from clientRef(). See Rich text extensions.
plugins
Plugin[]. Default: [].
Plugins from definePlugin(). They merge in list order, before your own hooks. See Plugins.
| Key | What it adds |
|---|---|
name | Required. Prefixes the routes and the task names |
collections, globals | Entries, like your own |
hooks, mediaHooks | Hooks for every entry, and for the media library |
routes | Routes under /_tenon/<name> that need a session |
publicRoutes | Routes under /_tenon/<name> without a session |
middleware, publicMiddleware | Middleware for requests with a session, or for all |
jobs | tasks and scheduledTasks. Names start with <name>: |
richtext, admin | Editor extensions and admin parts |
seed, onInit, afterImport, afterError | Lifecycle hooks |
Startup checks
defineCms() checks the config when it loads, and throws before the first request.
secret,site.url,cors,databaseandmedia.storageare checked together. The errortenoncms: invalid configlists every problem among them.- Every other check throws on its own problem, like an unknown role in an access rule, a cron pattern without five fields or a webhook URL that is not http(s).
Related resources
- Configuration: the file, the environment variables and the routes Tenon adds.
- Local API: every method of
cms.