Skip to content

padlet/payload-cms

Repository files navigation

Payload Cloudflare Template

Deploy to Cloudflare

This can only be deployed on Paid Workers right now due to size limits. This template comes configured with the bare minimum to get started on anything you need.

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.

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 size limits

We currently recommend deploying this template to the Paid Workers plan due to bundle size limits of 3mb. We're actively trying to reduce our bundle footprint over time to better meet this metric.

This also applies to your own code, in the case of importing a lot of libraries you may find yourself limited by the bundle.

Questions

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •