A brief intro to the tech stack
Cloudflare Workers
It’s an umbrella term for Cloudflare’s serverless computing platform that let’s you run your code on their widespread global resources. You can deploy web applications, back-end services, host databases, run LLMs and more. Their massive CDN and caching capability handles fast delivery to my visitors pretty much anywhere.
I’ve utilized their generous free offering to deploy this static site blog.I choose to go with a static site and workers to reduce the overhead of having to manage an entire backend infrastructure for a simple blog. I implemented a CI/CD flow (using GitHub Actions) in 2024 to host my blog on AWS but it was a hassle to maintain the site. Cloudflare Worker has been an easy and wonderful experience for me so far.
Cloudflare Wrangler
It’s a tool for developers to interact and configure their Cloudflare Workers environment from the CLI.
- Preview your project locally before deploying to Worker. Wrangler emulates similar running conditions locally as on Cloudflare’s edge servers.
- Allows you to configure your Worker environment through Infrastructure-as-Code instead of going through the dashboard.
Astro Static Site Generator
This is a very brief overview of how the Astro Static Site Generator (SSG) works.
Astro is an independent web framework you can use to create static sites. It also gives you the flexibility to bring in components from your favorite frameworks like React and Angular.
Node.js (a JavaScript runtime environment) does all the heavy lifting of downloading the dependencies (for building the site) and compiling the Astro’s native code into standard code (HTML/CSS/JS) understandable by web servers and clients (including Cloudflare Worker - edge server).
Note that Node.js does not directly compile Astro code, instead it runs some custom JavaScript code (understandable by Node.js) that then compiles Astro code to standard code.
This standard code (HTML/CSS/JS) can now be served by most web servers including Cloudflare’s edge servers using its Workers product.
Where does GitHub come into play?
GitHub simply acts as the cloud code repository. You configure your Cloudflare Worker project to authenticate and pull your Astro project code from your GitHub repository. Cloudflare then uses npm (or pnpm depending on the project) to build and use it’s internal server engine (I think it’s Cloudflare V8 server-less engine) to serve your site.
Let’s deploy your first site …
-
Clone an Astro theme of your choice from it’s repository to your development environement.
The theme I currently use: https://github.com/satnaing/astro-paper
-
Clean up the cloned project by removing placeholder and sample files.
-
Add
.gitignorefile so you don’t push local build files and logs -
Install
Node.jsnpm(node’s package manager)I was trying to build this particular Astro theme locally using the standard
npmand it was giving me dependency errors.Later I realized this theme was build using the
pnpmecosystem and so I had to installpnpmpackage manager to configure this project.To install
node: grab the latest LTS binary from https://nodejs.org/en/blog/release/ and throw that binary in your/usr/local/bin/or create a soft link to a location in $PATH.To install
pnpmrun the official installation script:curl -fsSL https://get.pnpm.io/install.sh | sh - -
To install dependencies (nodejs packages) ,under the root of your project directory run:
pnpm install(the package list comes from
package.jsonfile) -
Install Cloudflare Wrangler
- Inside your local project run:
pnpm add -D wrangler@latest - Verify if it’s installed:
npx wrangler --version
- Inside your local project run:
-
Create your Wrangler Configuration File
wrangler.jsonc{ "name": "mysite", "compatibility_date": "YYYY-MM-DD", // Update to the day you deploy "assets": { "directory": "./dist", // build directory } } -
Specify your Node.JS runtime version for the worker in a version file. Create a file
.node-versionand enter in it your NodeJS version.The reason why I had to specify the node version was because I was getting the below build error. Specifying a version of 22 fixed it.
What’s confusing me still is according to their docs (https://developers.cloudflare.com/workers/ci-cd/builds/build-image/#overriding-default-versions), Cloudflare’s default build runtime is Node.JS version 22.16.0 which in fact should support my Astro node file that was built on version 22.12.


-
Let’s build and preview the project locally before deploying it to Cloudflare.
Since my project was created and managed using
pnpm, I’ll run the below build commands:pnpm buildThe “script” to build the project is described in
package.jsonfile under the root directory.To preview the project on localhost run:
npx wrangler dev --ip <IP-Address>(served at your IP interface for external access) -
When you’re satisfied with your work, create a GitHub repo (or Gitlab) and push all the files to it. This is the cloud repository for your site files.
Follow the below steps to configure a Cloudflare Worker, connect it to your GitHub repo and have it scan your default branch (which is
main) for any changes you push.When changes are pushed to the default branch, a production build is automatically triggered by the worker and publishes (or deploys) the built site.
-
Create a new Cloudflare worker project and connect it your GitHub repo
- Navigate to
Compute > Workers & Pages. SelectCreate application. - Under
Import a repository, select a Git account and then the repository containing your Astro project.

c. Since I’m the only person working on this blog and to keep things simple, I’ve used my
mainbranch as the production branch.If you want to change the production branch or setup a preview build branch, checkout: https://developers.cloudflare.com/workers/ci-cd/builds/build-branches/
- Navigate to
-
Let’s add the Build configuration variables.
Under the project Settings add the below:

NOTE: You can actually specify all your build config parameter in
wrangler.jsonc(step 7).Below is a screenshot of a successful build.

-
After a successful build and deploy, let’s see how people can reach your site.
Cloudflare provides an endpoint URL to use. You can view it under the Domains tab of your worker project.
However, if you like to bring your custom domain, you can do so easily by heading over to the Domains tab under your worker project and hit the Add Domain. Choose your domain from the list and confirm.
If your domain’s primary nameserver is a different service, you may have to look into setting up a CNAME record to point to the worker endpoint.

- A final touch is to redirect
wwwto your root domain- Head over to Rules > Overview
- Create Rule
- Add a Wildcard match for Request URL:
https://www.* - For Target URL:
https://${1}with a status Code of 301 and enable Preserve Query String - I’ll then ask you to create a DNS record for www. Just add a proxied A record for it and point it to 192.0.2.1 . This IP is just a dummy placeholder and acts as a front-end to Cloudflare’s routing engine so it redirects based on the set rules.