Vercel
On Vercel, Tenon runs in your site's serverless functions. A function keeps no files, so the database and the media files live outside it. This page sets up both, the variables, the job clock and preview deployments.
Before you start
- A Vercel project for your site.
- A project from
npm create tenoncms@latestwith the target Vercel, or a site set up as in Add to an existing site. - Astro needs the Vercel adapter,
@astrojs/vercel. Nuxt, TanStack Start and Standalone build for Vercel without extra config.
A walkthrough with Neon is at the end: Vercel with Neon.
Connect a database
A file in the function does not persist, so use Postgres or Turso.
Install pg and @vercel/functions. Use the pooled connection string of your provider, for example the host with -pooler on Neon:
import { attachDatabasePool } from "@vercel/functions";
import { postgres } from "tenoncms/postgres";
const database = postgres(process.env.DATABASE_URL!);
// Vercel suspends idle functions. Their idle connections MUST close first.
attachDatabasePool(database.pool);
export default defineCms({
database,
// ...
});
Install @libsql/client. Create a database and a token with the Turso CLI:
turso db create my-site
turso db show my-site --url
turso db tokens create my-site
import { libsql } from "tenoncms/libsql";
export default defineCms({
database: libsql({
url: process.env.DATABASE_URL!,
authToken: process.env.DATABASE_AUTH_TOKEN,
}),
// ...
});
In development, DATABASE_URL can stay a local file, like file:./cms.db.
Read the variables the way your framework does. See Environment variables. For more on each database, see Databases.
Store media in a bucket
The function's disk is read-only, so the default storage on the local disk does not work. Without a media option there is no media library, and media: true throws. Use any S3-compatible bucket, or R2 with API keys:
import { s3 } from "tenoncms/media/s3";
export default defineCms({
// ...
media: {
storage: s3({
bucket: process.env.S3_BUCKET!,
region: process.env.AWS_REGION!,
endpoint: process.env.AWS_ENDPOINT_URL_S3,
accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
}),
},
});
import { r2 } from "tenoncms/media/r2";
export default defineCms({
// ...
media: {
storage: r2({
accountId: process.env.CLOUDFLARE_ACCOUNT_ID!,
bucket: process.env.R2_BUCKET!,
accessKeyId: process.env.R2_ACCESS_KEY_ID!,
secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!,
}),
},
});
- The browser uploads straight to the bucket, so Vercel's 4.5 MB request limit does not apply. The bucket MUST allow
PUTfrom your site in its CORS rules and expose theETagheader. - Without
publicUrl, the bucket stays private. The function serves the files, and Vercel's CDN keeps them for up to an hour. prefixputs every file in a folder of the bucket, so several sites or a staging site can share one bucket.
See Media storage for CORS, publicUrl, prefix and lifecycle rules.
Resize images
vercel() from tenoncms/media/vercel uses Vercel Image Optimization. Turn it on in the framework config, with the same widths as images.sizes in tenon.config.ts. The default is [320, 640, 1024, 1536, 1920]:
// astro.config.ts
import vercel from "@astrojs/vercel";
export default defineConfig({
adapter: vercel({ imagesConfig: { sizes: [320, 640, 1024, 1536, 1920], domains: [] } }),
});
// nuxt.config.ts
export default defineNuxtConfig({
nitro: { vercel: { config: { images: { sizes: [320, 640, 1024, 1536, 1920], domains: [] } } } },
});
// vite.config.ts
const vercel = { config: { images: { sizes: [320, 640, 1024, 1536, 1920], domains: [] } } };
export default defineConfig({
plugins: [tanstackStart(), nitro({ vercel }), viteReact(), tenonAdmin()],
});
- Standalone sets the same
nitro({ vercel })invite.config.ts, withouttanstackStart()andviteReact(). - The Vercel starters write this config. Change both lists together.
- With
publicUrlon the bucket, also allow its host inremotePatternsof the sameimagesblock. - Outside Vercel,
vercel()returns the originals, so development needs nothing.
ipx() and the image services work on Vercel too. See Image providers.
Set the environment variables
Set them in Project Settings → Environment Variables. The starters use these names:
| Variable | What it is |
|---|---|
TENON_SECRET | Signs sessions. At least 32 characters: openssl rand -hex 32 |
TENON_SITE_URL | The production origin, like https://example.com |
DATABASE_URL | The pooled Postgres URL, or the Turso URL |
DATABASE_AUTH_TOKEN | The Turso token |
AWS_ENDPOINT_URL_S3 | S3: the endpoint of the bucket |
AWS_ACCESS_KEY_ID | S3: the access key |
AWS_SECRET_ACCESS_KEY | S3: the secret key |
AWS_REGION | S3: the region |
S3_BUCKET | S3: the bucket name |
S3_PREFIX | S3: a folder in the bucket. Optional |
CLOUDFLARE_ACCOUNT_ID | R2 and Cloudflare Email Service: your account ID |
R2_BUCKET | R2: the bucket name |
R2_ACCESS_KEY_ID | R2: the key of an R2 API token |
R2_SECRET_ACCESS_KEY | R2: the secret of that token |
CRON_SECRET | The token of the clock route. See Run the jobs |
- In Nuxt, each variable has the
NUXT_prefix, likeNUXT_TENON_SECRET. - Email adds its own:
SMTP_HOST,SMTP_PORT,SMTP_USER,SMTP_PASSWORDandEMAIL_FROMfor SMTP, orCLOUDFLARE_EMAIL_API_TOKENandEMAIL_FROMfor Cloudflare Email Service. - A hosted image service adds its URL variable. The starter lists every variable in
.env.example.
Vercel also gives the variables to the build. A build that prerenders pages loads tenon.config.ts and reads the database, so it needs the same values as the functions.
Run the jobs
Vercel has no process that keeps running, so nothing ticks the job clock by itself. The Vercel starters turn the built-in clock off:
| Framework | On Vercel |
|---|---|
| Astro | No built-in clock |
| Nuxt | Nitro 2 makes no Vercel Cron Job, so the task never runs. The starter sets tenonCms: { jobs: false }. The module warns in a Vercel build without it |
| TanStack Start, Standalone | Nitro 3 makes a Vercel Cron Job every minute. The starter sets tenonAdmin({ jobs: false }), because of the Hobby limit |
Call the clock route instead. Set a secret, and the route /_tenon/jobs/run appears:
export default defineCms({
// ...
jobs: { secret: process.env.CRON_SECRET },
});
Then tick it every minute:
- On Hobby, call it from an outside cron service with the header
Authorization: Bearer <CRON_SECRET>. - On Pro, add a Vercel Cron Job. Vercel sends
CRON_SECRETas that header:vercel.json{ "crons": [{ "path": "/_tenon/jobs/run", "schedule": "* * * * *" }] }
On TanStack Start and Standalone, you can removejobs: falseinstead. Nitro then adds the cron job.
Without a clock, scheduled publishing, queued jobs and webhooks wait.
Preview deployments and prerendered pages
TENON_SITE_URL fixes the origin of sign-in. A preview deployment runs on another host, so sign-in there fails with the production URL. Pick one:
- Leave
TENON_SITE_URLunset for the Preview environment. Auth then uses the host of each request. - Give previews a fixed domain, like
preview.example.com, and list it inauth.baseURL:tenon.config.tsexport default defineCms({ // ... auth: { baseURL: { allowedHosts: ["example.com", "preview.example.com"], fallback: "https://example.com", }, }, });
A passkey works only on the host it was created on.
DATABASE_URL writes to production content. If it runs a newer tenoncms, its first request also migrates the production database. Give the Preview environment its own database and bucket.A prerendered page shows the content of the last build. To keep it current:
- Give the collection a
previewURL that renders per request, so editors see drafts before a build. See Prerendered pages and preview routes. - Start a new build after each publish with a Vercel deploy hook, from Project Settings → Git → Deploy Hooks.
Walkthrough: Vercel with Neon
Neon has Postgres and S3-compatible object storage in one project. This walkthrough takes a project from npm create tenoncms@latest, with the target Vercel, the database Postgres and the storage S3.
Create the Neon project
Create a Neon project in the region of your Vercel functions, for example aws-eu-central-1 for fra1.
Copy the database URL
Copy the pooled connection string, with -pooler in the host. It is DATABASE_URL.
Create the bucket
Create a bucket in the project's object storage and keep its access private. Copy these values:
| From Neon | Variable |
|---|---|
| The S3 endpoint | AWS_ENDPOINT_URL_S3 |
| The access key | AWS_ACCESS_KEY_ID |
| The secret key | AWS_SECRET_ACCESS_KEY |
| The region | AWS_REGION |
| The bucket name | S3_BUCKET |
A new Neon bucket allows PUT from every origin and exposes ETag, which uploads need. To allow only your site, send PutBucketCors with the S3 API.
Set the variables in Vercel
Set the variables from the last two steps, TENON_SECRET from openssl rand -hex 32, and TENON_SITE_URL with the production origin. In Nuxt, add the NUXT_ prefix to each.
Deploy and sign in
Deploy the project. Open /admin and create the first admin.
Neon stores lifecycle rules but does not run them, so the bucket does not clean up unfinished uploads. Each Neon branch has its own buckets.
Related resources
- Deployment overview: what every deployment needs, and a checklist.
- Media storage: CORS,
publicUrl,prefixand lifecycle rules. - The clock: the clock route and how often it runs.
- Authentication: the CMS origin and
allowedHosts. - Headless: a CMS on Vercel for a site on another origin.