With Cloudflare D1

Official

Blank Payload starter for Cloudflare Workers with a D1 SQLite database and R2 media storage

Payloadcms official
1 / 1
Payloadcms official

Overview

Summary generated from the README

A minimal Payload starter configured to run on Cloudflare Workers using Next.js through OpenNext. It uses the D1 SQLite adapter for the database and an R2 bucket for uploaded media, with Users and Media collections preconfigured. Requires a Cloudflare account and Wrangler, and targets a Payload 4 beta release.

Features

  • Cloudflare D1 SQLite database adapter
  • R2 bucket storage for the Media uploads collection
  • Users auth collection with admin panel access
  • Console-based logger compatible with Cloudflare Workers
  • Deploy script that runs migrations, builds and deploys through Wrangler
  • Vitest and Playwright testing setup

Good for

  • Building a Payload project hosted entirely on Cloudflare Workers
  • Starting a lightweight site or API that needs D1 and R2 without external services

From the author

A blank template to get started with Payload

Get started

npx create-payload-app -t with-cloudflare-d1

README

Payload Cloudflare Template

Deploy to Cloudflare

This template comes configured with the bare minimum to get started on anything you need. See Worker limits for deployment limits.

Quick start

This template can be deployed directly to Cloudflare Workers by clicking the button to take you to the setup screen.

From there you can connect your code to a git provider such Github or Gitlab, name your Workers, D1 Database and R2 Bucket as well as attach any additional environment variables or services you need.

Quick Start - local setup

To spin up this template locally, follow these steps:

Clone

After you click the Deploy button above, you'll want to have standalone copy of this repo on your machine. Cloudflare will connect your app to a git provider such as Github and you can access your code from there.

Local Development

How it works

Out of the box, using Wrangler will automatically create local bindings for you to connect to the remote services and it can even create a local mock of the services you're using with Cloudflare.

We've pre-configured Payload for you with the following:

Collections

See the Collections docs for details on how to extend this functionality.

  • Users (Authentication)

    Users are auth-enabled collections that have access to the admin panel.

    For additional help, see the official Auth Example or the Authentication docs.

  • Media

    This is the uploads enabled collection.

Image Storage (R2)

Images will be served from an R2 bucket which you can then further configure to use a CDN to serve for your frontend directly.

D1 Database

The Worker will have direct access to a D1 SQLite database which Wrangler can connect locally to, just note that you won't have a connection string as you would typically with other providers.

You can enable read replicas by adding readReplicas: 'first-primary' in the DB adapter and then enabling it on your D1 Cloudflare dashboard. Read more about this feature on our docs.

Working with Cloudflare

Firstly, after installing dependencies locally you need to authenticate with Wrangler by running:

pnpm wrangler login

This will take you to Cloudflare to login and then you can use the Wrangler CLI locally for anything, use pnpm wrangler help to see all available options.

Wrangler is pretty smart so it will automatically bind your services for local development just by running pnpm dev.

Deployments

When you're ready to deploy, first make sure you have created your migrations:

pnpm payload migrate:create

Then run the following command:

pnpm run deploy

This will spin up Wrangler in production mode, run any created migrations, build the app and then deploy the bundle up to Cloudflare.

That's it! You can if you wish move these steps into your CI pipeline as well.

Enabling logs

By default logs are not enabled for your API, we've made this decision because it does run against your quota so we've left it opt-in. But you can easily enable logs in one click in the Cloudflare panel, see docs.

Logger Configuration

This template includes a custom console-based logger compatible with Cloudflare Workers. Payload's default logger uses pino-pretty, which relies on Node.js APIs not available in Workers and would cause fs.write is not implemented errors.

The custom logger in payload.config.ts:

  • Routes logs through console.* methods which Workers handles correctly
  • Outputs JSON-formatted logs for Cloudflare observability
  • Only active in production (development uses the default pino-pretty for better DX)

You can control the log level via the PAYLOAD_LOG_LEVEL environment variable (e.g., debug, info, warn, error).

Diagnostic Channel Errors

If you see "Failed to publish diagnostic channel message" errors in your observability logs, these typically come from the undici HTTP client library. The template includes skipSafeFetch: true in the Media collection to use native fetch instead of undici for file uploads, which helps reduce these errors.

Cloudflare Workers runs in an isolated environment that cannot access private IP ranges by default, providing built-in SSRF protection. This makes skipSafeFetch safe to use.

Known issues

GraphQL

We are currently waiting on some issues with GraphQL to be fixed upstream in Workers so full support for GraphQL is not currently guaranteed when deployed.

Worker limits

Workers Free and Workers Paid both have a Worker size limit of 64 MiB uncompressed, with no compressed size limit. This includes your application code and its dependencies.

The Workers Free plan has a CPU time limit of 10 ms per HTTP request, which authentication and server-side rendering workloads can exceed.

Questions

If you have any issues or questions, reach out to us on Discord or start a GitHub discussion.

More Starters & boilerplates templates

mi-proyecto-2026 screenshot

mi-proyecto-2026

Blank Payload 3 starter on Next.js 16 with Turso SQLite storage and Cloudflare R2 media uploads

12
v3
Next.js
Updated 1 months ago
With Postgres screenshot

With Postgres

Official

Blank Payload starter on Next.js using the Postgres database adapter and local disk storage

v4
Next.js
Updated 3 days ago
With Vercel Postgres screenshot

With Vercel Postgres

Official

Blank Payload starter for Next.js with Vercel Postgres and Vercel Blob storage

v4
Next.js
Updated 3 days ago