Deploying Nuxt App to Cloudflare Pages/Workers

This guide provides the technical workflow for deploying a Nuxt application (created from the `Nuxt Auto-CRUD Template`) to Cloudflare using D1 (SQLite/libSQL) and Wrangler.

🛠 Prerequisites

  • Cloudflare Account with D1 enabled.
  • Project built with Nuxt 4+ and Drizzle ORM.
  • Wrangler CLI installed.

1. Cloudflare D1 Database Provisioning

Before deploying the application, you must provision the production database instance.

2. Configure wrangler.toml for Nuxt

Ensure your configuration maps the Cloudflare bindings to your Nuxt environment.

# wrangler.toml
name = "your-project-name" # Must match Cloudflare project name
compatibility_date = "2026-01-21"
main = ".output/server/index.mjs"

compatibility_flags = ["nodejs_compat"]

[[d1_databases]]
binding = "DB" # The binding name used in your Drizzle config
database_name = "your-db-name"
database_id = "your-db-id"
migrations_dir = "server/db/migrations/sqlite"

[assets]
directory = ".output/public"
binding = "ASSETS"

[observability]
enabled = true
head_sampling_rate = 1

3. Remote Schema Migrations (Drizzle)

Push your local schema changes to the live Cloudflare D1 production instance.

# Using Wrangler directly
npx wrangler d1 migrations apply <DATABASE_NAME> --remote

# Alternative via NAC template shortcut
bun migrate:remote

4. Production Deployment on Cloudflare

  1. Dashboard: Go to Compute & AI > Workers & Pages > Create Application.
  2. Connect: Select your Git Repository.
  3. Build Settings: Ensure the project name aligns with your wrangler.toml.
  4. Deploy: Trigger the initial build.

5. Required Environment Variables

Configure these secrets in the Cloudflare Dashboard to enable Nuxt Auto-CRUD security and admin hydration.

VariableImportancePurpose
NUXT_SESSION_PASSWORDCritical32+ character string for session encryption.
NUXT_ADMIN_EMAILRequiredThe email used to trigger the initial db:seed.
NUXT_ADMIN_PASSWORDRequiredDefault credential for first-time access.

6. Admin & RBAC Initialization

Once deployed, access your URL and sign in.

  • Seed Trigger: The first login with NUXT_ADMIN_EMAIL automatically hydrates roles and permissions via the internal seed task.
  • Security Audit: Navigate to Settings (User Avatar > Settings) and verify that Session Security and Admin Access are toggled to 'secure'.
  • Permissions: Use the built-in Admin UI to define granular RBAC rules. Video Tutorial: RBAC Setup