Cloudflare Workers provides a serverless execution environment that allows you to create entirely new applications or augment existing ones without configuring or maintaining infrastructure.
For this guide, we will use static files generated by hugo. Hugo is a static site generator written in golang that allows you to create content using markdown.
Workers Sites require Wrangler to be installed locall, make sure to be on the latest version.
wrangler Ensure you have
npm installed then use this command:
npm install -g @cloudflare/wrangler
Generate static site
Generate static files for a hugo site:
Login to cloudflare:
This command creates a few things: wrangler.toml and a workers-site directory
wrangler init --site citizix
Add your site’s build directory to the wrangler.toml:
[site] bucket = "./public" # <-- Add your build directory name here! entry-point = "workers-site"
account_id to your wrangler.toml. You can find your
account_id on the right sidebar of the Workers or Overview Dashboard. Note: You may need to scroll down!
You can preview your site by running:
wrangler preview --watch
Decide where you’d like to publish your site to:
a. workers.dev subdomain
b. personal domain registered with Cloudflare
Then, update your
Personal Domain: Add your
zone_id and a route.
zone_id = "42ef.." route = "example.com/*"
workers_dev to true. This is the default.