Deploying an Astro blog on Cloudflare
| Created: | |
| Updated: | |
| Written by: | AI |
AI-assisted content. A human was involved, but the AI did most of the heavy lifting.
Building a modern blog doesn’t have to be complicated. In this guide, I’ll walk you through setting up an Astro blog, deploying it to Cloudflare Workers, managing it with GitHub, and developing it efficiently using Cursor IDE.
Why This Stack?
- Astro: Fast, modern static site generator with excellent developer experience
- Cloudflare Workers: Global edge deployment with excellent performance
- GitHub: Version control and collaboration
- Cursor: AI-powered IDE that accelerates development
Prerequisites
Before we begin, make sure you have:
- Node.js 18+ installed
- A GitHub account
- A Cloudflare account
- Cursor IDE installed (or any code editor)
- Basic familiarity with command line
Step 1: Create Your Astro Project
Using the Cloudflare Template
The easiest way to get started is using Cloudflare’s Astro blog template:
npm create cloudflare@latest my-blog -- --template=cloudflare/templates/astro-blog-starter-template
This command will:
- Create a new Astro project
- Set up Cloudflare Workers integration
- Include blog functionality out of the box
Manual Setup
If you prefer to set it up manually:
npm create astro@latest my-blog
cd my-blog
npm install @astrojs/cloudflare
Then configure astro.config.mjs:
import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';
export default defineConfig({
output: 'server',
adapter: cloudflare(),
});
Step 2: Set Up GitHub Repository
Initialize Git
git init
git add .
git commit -m "Initial commit: Astro blog setup"
Create GitHub Repository
- Go to GitHub and create a new repository
- Don’t initialize it with a README (we already have files)
- Copy the repository URL
Connect and Push
git remote add origin https://github.com/yourusername/my-blog.git
git branch -M main
git push -u origin main
Step 3: Configure Cloudflare Workers
Install Wrangler CLI
npm install -D wrangler
Authenticate with Cloudflare
npx wrangler login
This will open your browser to authenticate with Cloudflare.
Configure Wrangler
Create or update wrangler.json:
{
"name": "my-blog",
"compatibility_date": "2024-01-01",
"compatibility_flags": ["nodejs_compat"]
}
Deploy
npm run build
npx wrangler deploy
Your blog should now be live on Cloudflare Workers!
Step 4: Develop with Cursor IDE
Why Cursor?
Cursor is an AI-powered IDE that makes development faster:
- AI Code Completion: Get intelligent suggestions as you type
- Chat with Your Codebase: Ask questions about your code
- Refactoring Assistance: Let AI help you improve code structure
- Error Detection: Catch issues before they become problems
Setting Up Cursor
- Install Cursor: Download from cursor.sh
- Open Your Project: File → Open Folder → Select your blog directory
- Configure Settings:
- Enable TypeScript support
- Set up Astro language server
- Configure Git integration
Using Cursor for Blog Development
Cursor excels at:
- Writing Content: Use AI to help draft blog posts
- Component Creation: Generate Astro components quickly
- Styling: Get CSS suggestions and improvements
- Debugging: Ask Cursor to help fix errors
Step 5: Set Up CI/CD Pipeline
GitHub Actions Workflow
Create .github/workflows/deploy.yml:
name: Deploy to Cloudflare Workers
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: npm ci
- run: npm run build
- uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
Add Cloudflare Secrets
- Go to GitHub repository → Settings → Secrets
- Add
CLOUDFLARE_API_TOKENwith your Cloudflare API token - Get your token from Cloudflare Dashboard → My Profile → API Tokens
Now every push to main will automatically deploy!
Step 6: Customize Your Blog
Update Site Information
Edit src/consts.ts:
export const SITE_TITLE = "Your Blog Name";
export const SITE_DESCRIPTION = "Your blog description";
Customize Theme
- Edit
src/styles/global.cssfor colors and styling - Update components in
src/components/ - Modify layouts in
src/layouts/
Add Content
Create new blog posts in src/content/articles/:
---
title: "My First Post"
description: "Post description"
pubDate: "2024-12-20"
---
Your post content here...
Best Practices & Troubleshooting
Development Workflow
- Local Development: Use
npm run devfor local testing - Preview Build: Run
npm run previewbefore deploying - Version Control: Commit frequently with descriptive messages
- Branch Strategy: Use feature branches for new posts/features
Performance Tips
- Optimize images before adding them
- Use Astro’s built-in image optimization
- Enable Cloudflare’s caching features
- Minimize JavaScript where possible
Security
- Keep dependencies updated
- Use environment variables for secrets
- Enable Cloudflare’s security features
- Review code before deploying
Common Issues
Build Fails: Check Node.js version (need 18+), clear node_modules and reinstall, verify astro.config.mjs is correct.
Deployment Issues: Verify Cloudflare API token is correct, check wrangler.json configuration, ensure build completes successfully.
Cursor Not Working: Restart Cursor, check TypeScript/Astro extensions installed, verify project is opened correctly.
Next Steps
Now that your blog is set up:
- Write Your First Post: Start sharing your thoughts
- Customize Design: Make it your own
- Add Features: Consider adding comments, analytics, or RSS
- Optimize: Monitor performance and improve over time
Conclusion
Setting up an Astro blog on Cloudflare Workers with GitHub and Cursor gives you:
- ✅ Fast, global deployment
- ✅ Excellent developer experience
- ✅ Version control and collaboration
- ✅ AI-powered development assistance
This stack provides a solid foundation for a modern, performant blog that’s easy to maintain and extend.
Happy blogging!