An opinionated starter for Astro on Cloudflare Workers, based on the setup I use for Innerhelm, Evelyn Escobar Art, my personal site, and other projects.
- Deploys to Cloudflare's global edge network using Workers
- Uses GitHub actions for its deploy pipeline, powering daily builds and PR previews
- Uses the @astrojs/cloudflare adapter and Astro's new intelligent
staticbuild mode. This allows you to opt-in to SSR on a per-route basis by addingexport const prerender = falseto a route. - Provides other niceties to speed up development, outlined below.
- Use this repo as a template by clicking the "Use this template" button at the top of the GitHub page.
- Clone your new repository to your local machine:
git clone https://github.com/your-username/your-new-repo.git cd your-new-repo - Run the initialization script and follow the instructions:
bun ./scripts/init.ts
The script will handle installing dependencies (via pnpm), customizing your project name and theme, and setting up the necessary GitHub Secrets for automatic deployment to Cloudflare.
The folders in src have aliases that make it easy to reference their contents. Instead of needing to import (for example) ../../../utils/foobar.ts to pull a utility function into a route, you can import @utils/foobar.ts, from anywhere in your project.
Aliases are configured for the following directories:
assets- Image and other media filescontent- Your Astro Content Collectionscomponents- Reusable componentslayouts- Astro layoutspages- Astro routesutils- Other utilities. I keep utility functions in this folder, each with their own file.
Your site will automatically be built and deployed each day at 15:00 UTC. This allows you to do scheduled posts, by filtering out posts with a future date from each build.
To remove: Remove the cron trigger in .github/workflows/main.yml.
@layouts/Base.astro invokes the utility function logCommitHash (from @utils) to log the current build's commit hash on page load. This hash is provided by the deployment pipeline.
To remove: Delete src/utils/logCommitHash.ts, remove the script tag from src/layouts/Base.astro, and delete PUBLIC_COMMIT_HASH: ${{ ... }} from .github/workflows/main.yml.