Add wrangler.toml, deployment script, and documentation for deploying the AI Code Battle SPA to Cloudflare Pages. - wrangler.toml: Cloudflare Pages project configuration - scripts/deploy-pages.sh: Manual deployment script using wrangler CLI - web/CLOUDFLARE_DEPLOYMENT.md: Deployment guide with GitHub Actions setup Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2.6 KiB
2.6 KiB
Cloudflare Pages Deployment Guide
This guide explains how to deploy the AI Code Battle SPA to Cloudflare Pages.
Quick Start
Option 1: GitHub Integration (Recommended)
- Go to Cloudflare Dashboard
- Navigate to Workers & Pages > Create application > Pages > Connect to Git
- Select the
ai-code-battlerepository - Configure the build settings:
- Project name:
ai-code-battle - Production branch:
master - Build command:
cd web && npm run build - Build output directory:
web/dist
- Project name:
- Click Save and Deploy
The site will now automatically deploy whenever you push to the master branch.
Option 2: Manual Deployment with Wrangler
-
Install wrangler:
npm install -g wrangler -
Authenticate with Cloudflare:
wrangler login -
Build the site:
cd web npm install npm run build -
Deploy to Pages:
wrangler pages deploy dist --project-name=ai-code-battle
Environment Variables
For the GitHub Actions workflow to work, you need to set these secrets in your GitHub repository:
CLOUDFLARE_API_TOKEN: Your Cloudflare API tokenCLOUDFLARE_ACCOUNT_ID: Your Cloudflare account ID
Getting Your Credentials
-
API Token:
- Go to Cloudflare API Tokens
- Create a token with Edit Cloudflare Workers permissions
- Copy the token
-
Account ID:
- Go to any Cloudflare page
- Find your Account ID in the right sidebar
- Or run:
wrangler whoamiafter logging in
-
Add to GitHub:
- Go to your repository Settings > Secrets and variables > Actions
- Click New repository secret
- Add
CLOUDFLARE_API_TOKENandCLOUDFLARE_ACCOUNT_ID
Custom Domain
To use a custom domain (e.g., aicodebattle.com):
- Go to your Pages project in the Cloudflare Dashboard
- Navigate to Custom domains
- Add your domain
- Cloudflare will automatically configure the DNS
Verification
After deployment, verify the site is accessible:
- Pages URL:
https://ai-code-battle.pages.dev - Custom domain:
https://aicodebattle.com(if configured)
Troubleshooting
Build fails
- Make sure all dependencies are installed:
cd web && npm install - Check the build logs in the Cloudflare Dashboard
Authentication fails
- Make sure your API token has the correct permissions
- Verify your account ID is correct
Custom domain not working
- Check DNS propagation:
dig aicodebattle.com - Verify the custom domain status in the Cloudflare Dashboard