In this guide, you’ll learn how to set up a static blog using Astro and host it on Cloudflare.
Cloudflare offers free static hosting with no limit on traffic.
Astro is a modern JavaScript framework and popular static site generator.
Requirements
For this guide, you will need:
- A GitHub account
- A Cloudflare account
- Node.js installed (
v18.20.8
orv20.3.0
,v22.0.0
or higher) - git installed
To make sure you have git
and node
installed, run in a terminal window:
git --versionnode --version
You should see version numbers if they are installed correctly.
Project setup
Open a terminal window and run the following command to start the Astro setup:
npm create astro@latest
Enter a name for the new project (for example ./astro-blog
). A new folder will be created for it.
Select the blog template and “Yes” to installing dependencies and initializing a git repository.
If everything worked correctly, you should see the following message:
Run these commands to enter the new project folder and start the development server:
cd ./astro-blognpm run dev
Once setup is complete, it will display a message that your blog is available at http://localhost:4321/ by default.
When you edit and save a file, the development server will detect the changes and reload the browser page automatically.
Uploading to GitHub
Once you’re ready to publish your blog, you will need to push it to a GitHub repository.
Create a new repository on GitHub and follow the instructions to push your blog to the repository.
You can set the repository to public or private, it doesn’t matter.
As you chose “Yes” to initializing a git repository, all you need to do is set the remote and push:
# replace <URL> with your remote URL from GitHubgit remote add origin <URL>git push -u origin HEAD
Deploying to Cloudflare
To deploy your blog to the web, you need to connect Cloudflare to your new GitHub repository.
Sign in to the Cloudflare dashboard and head to Workers & Pages, then click the “Create application” button.
Choose “Import a repository”, authenticate with GitHub, and select your new GitHub repository.
Enter a project name and click the “Create and deploy” button. Leave the rest of the options at their defaults.
That’s it! After a few moments, Cloudflare will build your blog and deploy it to the web.
Conclusion
Now that you have linked Cloudflare to your GitHub repository, it will automatically monitor and deploy any changes that you push.
You now have a fully automated workflow for maintaining your blog.