Overview
Astro Portfolio v3 is configured to deploy seamlessly to Cloudflare Pages using the official@astrojs/cloudflare adapter. The project is set up for SSR (Server-Side Rendering) mode, enabling dynamic functionality while benefiting from Cloudflare’s global edge network.
Adapter Configuration
The project uses the Cloudflare adapter configured inastro.config.mjs:9-16:
Deployment Process
Connect Your Repository
- Log in to the Cloudflare Dashboard
- Navigate to Pages in the sidebar
- Click Create a project
- Select Connect to Git
- Authorize Cloudflare to access your GitHub repository
- Select the repository containing your Astro portfolio
Configure Build Settings
Set the following build configuration:
| Setting | Value |
|---|---|
| Production branch | main |
| Build command | pnpm build |
| Build output directory | dist |
| Node version | 20 or higher |
The project uses
pnpm as the package manager. Cloudflare Pages will automatically detect this from the pnpm-lock.yaml file.Set Environment Variables
Configure the required environment variables in the Cloudflare Pages dashboard:
BEEHIIV_PUBLICATION_ID- Your Beehiiv publication IDBEEHIIV_API_KEY- Your Beehiiv API key (mark as secret)GTM_ID- Your Google Tag Manager ID
Wrangler Configuration
The project includes awrangler.jsonc configuration file for advanced Cloudflare Workers settings:
The
nodejs_compat compatibility flag enables Node.js runtime APIs required by the Astro server components.Automatic Deployments
Once connected, Cloudflare Pages automatically deploys your site:Production Deployments
- Trigger: Push to the
mainbranch - URL: Your custom domain or
[project-name].pages.dev - Process: Automatic build and deployment on every commit
Preview Deployments
- Trigger: Pull requests to any branch
- URL: Unique preview URL for each PR (e.g.,
[commit-hash].[project-name].pages.dev) - Features:
- Test changes before merging
- Share previews with stakeholders
- Automatic updates on new commits
Preview deployments use the same build configuration and environment variables as production, ensuring consistency across environments.
Build Output
The Cloudflare adapter produces:dist/_worker.js/index.js- The Cloudflare Workers runtime entry pointdist/- Static assets and rendered pages- Server-side rendering capabilities for dynamic routes
Performance Features
Deploying to Cloudflare Pages provides:- Global CDN: Content served from 300+ data centers worldwide
- Edge Computing: Server-side rendering at the edge for minimal latency
- Automatic Caching: Static assets cached automatically
- DDoS Protection: Built-in security and protection
- Unlimited Bandwidth: No additional costs for traffic
Troubleshooting
Common Issues
Build command not found: Make surepnpm is properly detected. Cloudflare Pages automatically detects package managers from lock files.
Environment variables not working: Ensure variables are set in the Cloudflare Pages dashboard, not just in your local .env file.
404 errors on routes: Verify that output: 'server' is set in astro.config.mjs for SSR routes.
Next Steps
Environment Variables
Configure API keys and secrets
Custom Domain
Set up your custom domain