Deployment

Vercel

Run Tenon in Vercel functions with Postgres or Turso and a bucket.

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@latest with 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:

tenon.config.ts
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,
  // ...
});

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:

tenon.config.ts
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!,
    }),
  },
});
  • The browser uploads straight to the bucket, so Vercel's 4.5 MB request limit does not apply. The bucket MUST allow PUT from your site in its CORS rules and expose the ETag header.
  • Without publicUrl, the bucket stays private. The function serves the files, and Vercel's CDN keeps them for up to an hour.
  • prefix puts 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: [] } }),
});
  • Standalone sets the same nitro({ vercel }) in vite.config.ts, without tanstackStart() and viteReact().
  • The Vercel starters write this config. Change both lists together.
  • With publicUrl on the bucket, also allow its host in remotePatterns of the same images block.
  • 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:

VariableWhat it is
TENON_SECRETSigns sessions. At least 32 characters: openssl rand -hex 32
TENON_SITE_URLThe production origin, like https://example.com
DATABASE_URLThe pooled Postgres URL, or the Turso URL
DATABASE_AUTH_TOKENThe Turso token
AWS_ENDPOINT_URL_S3S3: the endpoint of the bucket
AWS_ACCESS_KEY_IDS3: the access key
AWS_SECRET_ACCESS_KEYS3: the secret key
AWS_REGIONS3: the region
S3_BUCKETS3: the bucket name
S3_PREFIXS3: a folder in the bucket. Optional
CLOUDFLARE_ACCOUNT_IDR2 and Cloudflare Email Service: your account ID
R2_BUCKETR2: the bucket name
R2_ACCESS_KEY_IDR2: the key of an R2 API token
R2_SECRET_ACCESS_KEYR2: the secret of that token
CRON_SECRETThe token of the clock route. See Run the jobs
  • In Nuxt, each variable has the NUXT_ prefix, like NUXT_TENON_SECRET.
  • Email adds its own: SMTP_HOST, SMTP_PORT, SMTP_USER, SMTP_PASSWORD and EMAIL_FROM for SMTP, or CLOUDFLARE_EMAIL_API_TOKEN and EMAIL_FROM for 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:

FrameworkOn Vercel
AstroNo built-in clock
NuxtNitro 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, StandaloneNitro 3 makes a Vercel Cron Job every minute. The starter sets tenonAdmin({ jobs: false }), because of the Hobby limit
Vercel Hobby allows one cron job a day, and a deploy with a cron every minute fails.

Call the clock route instead. Set a secret, and the route /_tenon/jobs/run appears:

tenon.config.ts
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_SECRET as that header:
    vercel.json
    {
      "crons": [{ "path": "/_tenon/jobs/run", "schedule": "* * * * *" }]
    }
    

    On TanStack Start and Standalone, you can remove jobs: false instead. 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_URL unset for the Preview environment. Auth then uses the host of each request.
  • Give previews a fixed domain, like preview.example.com, and list it in auth.baseURL:
    tenon.config.ts
    export 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.

A preview deployment with the production 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:

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 NeonVariable
The S3 endpointAWS_ENDPOINT_URL_S3
The access keyAWS_ACCESS_KEY_ID
The secret keyAWS_SECRET_ACCESS_KEY
The regionAWS_REGION
The bucket nameS3_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.