Skip to content

Latest commit

 

History

History
44 lines (35 loc) · 1.59 KB

File metadata and controls

44 lines (35 loc) · 1.59 KB

Claude Code Learning Notes

Cloudflare Workers Deployment Lessons

Authentication

  • Use API token method for reliable authentication: CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID
  • Browser OAuth login can timeout in headless environments
  • Export environment variables before running Wrangler commands

Next.js Static Export to Cloudflare Workers

  • Configure wrangler.toml with [assets] section pointing to ./out directory
  • Use next build (not next export - it's deprecated)
  • Add deploy script to package.json: "deploy": "npm run build && wrangler deploy"

Common Configuration Issues

  1. _headers file format: Cloudflare expects specific format, remove if causing issues
  2. _redirects infinite loops: Avoid /* /index.html 200 patterns that create loops
  3. Environment specification: Use --env production to avoid environment warnings

Successful Deployment Process

# 1. Set environment variables
export CLOUDFLARE_API_TOKEN="your-token"
export CLOUDFLARE_ACCOUNT_ID="your-account-id"

# 2. Build the project
npm run build

# 3. Deploy to specific environment
npx wrangler deploy --env production

GitHub Setup

  • Use GitHub CLI for repository creation: gh repo create name --public --source=. --remote=origin --push
  • Configure Git identity before commits
  • Handle existing repository names by connecting to existing repo

File Structure for Cloudflare Workers

wrangler.toml - Worker configuration with [assets] section
out/ - Next.js build output directory
package.json - Include deploy script
.env.local - Environment variables (not committed)