Deploy SveltyCMS to Vercel — Serverless SvelteKit Headless CMS
Step-by-step guide to deploying SveltyCMS on Vercel with serverless databases (Neon PostgreSQL, MongoDB Atlas, PlanetScale) and S3/R2 media storage.
On this page
Deploying SveltyCMS to Vercel leverages SvelteKit’s native serverless adapter. Because serverless environments utilize ephemeral filesystems, this guide covers configuring cloud databases (Neon PostgreSQL, MongoDB Atlas), persistent object storage (Cloudflare R2, AWS S3), and required production environment variables.
Vercel Serverless Architecture & Ephemeral Filesystem Mechanics
When deploying on Vercel’s serverless infrastructure:
- Why SQLite Cannot Run on Vercel: Vercel functions execute in stateless, short-lived micro-VM containers (AWS Lambda / Firecracker). Any files written to the local disk (such as
data/sveltycms.dbor uploads inmediaFolder/) are destroyed when the execution instance shuts down or a new cold start initializes. - Persistent Data Tier: For production Vercel deployments, connect a serverless database over TCP or WebSocket (such as Neon Serverless PostgreSQL via
@neondatabase/serverlessor MongoDB Atlas). - Persistent Media Tier: Media uploads stream directly to S3-compatible cloud object storage (Cloudflare R2, AWS S3, or Backblaze B2), ensuring asset URLs remain permanent and globally edge-cached.
Quick Start
1. Prepare your database
Choose one of these hosted options:
| Database | Provider | Free Tier | Setup Time |
|---|---|---|---|
| MongoDB | MongoDB Atlas | ✅ 512MB | ~5 min |
| PostgreSQL | Neon | ✅ 0.5GB | ~2 min |
| MySQL/MariaDB | PlanetScale | ✅ 5GB | ~3 min |
Create a database and copy the connection string. You’ll use it in step 3.
2. Prepare media storage
Create an S3-compatible bucket for uploaded media:
| Provider | Free Tier | Notes |
|---|---|---|
| Cloudflare R2 | ✅ 10GB | No egress fees |
| AWS S3 | 5GB free tier | Standard choice |
| Backblaze B2 | ✅ 10GB | S3-compatible API |
3. Deploy to Vercel
# Install Vercel CLI
bun add -g vercel
# Deploy from your project root
vercel
When prompted, configure these settings:
Build Command: bun run build
Output Directory: .svelte-kit/vercel
Install Command: bun install
Environment Variables
Set these in your Vercel project dashboard (Settings → Environment Variables):
# ── Database ─────────────────────────
DB_TYPE=mongodb # mongodb | postgresql | mysql
DB_HOST=cluster0.xxxxx.mongodb.net # Your Atlas cluster host
DB_NAME=sveltycms
DB_USER=admin
DB_PASSWORD=your-db-password
# ── Auth Secrets ─────────────────────
JWT_SECRET_KEY=your-64-char-random-string
ENCRYPTION_KEY=your-32-char-random-string
# ── Media Storage ────────────────────
MEDIA_STORAGE=s3 # s3 | r2 | cloudinary
S3_ENDPOINT=https://xxx.r2.cloudflarestorage.com
S3_BUCKET=sveltycms-media
S3_REGION=auto
S3_ACCESS_KEY=your-access-key
S3_SECRET_KEY=your-secret-key
# ── Optional ─────────────────────────
MULTI_TENANT=false
USE_REDIS=false # Redis not needed for single-instance
SITE_NAME=My CMS
ORIGIN=https://your-app.vercel.app
Generate secure random strings with:
bun -e "console.log(crypto.randomBytes(32).toString('hex'))"
How it works on Vercel
SveltyCMS uses SvelteKit’s Vercel adapter to split your app into serverless functions:
┌─────────────────────────────────────────────┐
│ Vercel │
│ │
│ / → Edge Function (SSR) │
│ /api/* → Serverless Function │
│ /_app/* → Static Assets (CDN) │
│ /files/* → Redirected to S3 │
│ │
│ ┌─────────────────┐ ┌──────────────────┐ │
│ │ MongoDB Atlas │ │ Cloudflare R2 │ │
│ │ (content + auth) │ │ (media storage) │ │
│ └─────────────────┘ └──────────────────┘ │
└─────────────────────────────────────────────┘
Per-request boot: Each Vercel function initializes the database adapter, auth, and content system on cold start. Our progressive initialization keeps this under 1 second (vs. persistent Node.js servers where it’s instant).
Cold starts: Vercel functions are recycled after inactivity. The first request after a cold period triggers a full boot, then subsequent requests reuse the warm function. Our <1s cold start target is maintained.
Limitations vs self-hosted
| Feature | Self-hosted | Vercel |
|---|---|---|
| SQLite | ✅ | ❌ (ephemeral FS) |
| Local file storage | ✅ | ❌ (use S3) |
| WebSockets (Yjs) | ✅ | ❌ (use Vercel’s WS support or external) |
| Background jobs | ✅ | ⚠️ (use Vercel Cron) |
| Redis | ✅ | ✅ (Upstash) |
| Multi-tenant | ✅ | ✅ |
| Cold start | Instant | <1s progressive |
Production checklist
- Generate strong
JWT_SECRET_KEYandENCRYPTION_KEY - Enable MongoDB Atlas IP allowlist (or use
0.0.0.0/0+ strong password) - Configure S3 bucket CORS for your Vercel domain
- Set
ORIGINto your Vercel URL - Enable Vercel Analytics for traffic monitoring
- Add a custom domain in Vercel dashboard