Deploying to Cloudflare Workers
Cloudflare Workers is a serverless platform for creating entirely new applications or augmenting existing ones without configuring or maintaining infrastructure. With Workers Sites you can build any static site locally (e.g. your Gatsby project), and deploy to a workers.dev subdomain or custom domain.
This guide will get you started in a few steps:
- Installing wrangler CLI
- Initialize the Project
To create the Worker code that will serve your Gatsby files, from the root of your Gatsby project run:
You’ll notice your project structure should now look something like:
- Build the project
To run your application on Cloudflare Workers Sites, you first need to build your application locally. This should generate your files in
To authenticate into your Cloudflare account run:
Follow the Quick Start for steps on gathering the correct account ID and API token to link wrangler to your Cloudflare account.
If you don’t already have a workers.dev domain run:
Then, add your account ID to the
wrangler.toml file, and set
"./public", which is where Gatsby’s built files are output by default:
This deploys to your workers.dev subdomain. For a custom domain see Quick Start.
You can deploy your application by running the following command in the root of the project directory:
Now your site is available at gatsby-project.subdomain.workers.dev!
- CI with GitHub Actions
Once GitHub Actions is enabled on your repo, add a file to your project’s root called
.github/workflows/main.yml with the contents:
CF_API_TOKEN in GitHub secrets with appropriate values from Quick Start.