|
| 1 | +# Cloudflare Account Setup |
| 2 | + |
| 3 | +This command helps you configure your Cloudflare account credentials and GitHub secrets for deployment. Run this before your first deployment. |
| 4 | + |
| 5 | +## Prerequisites Check |
| 6 | + |
| 7 | +Before we begin, let me verify your environment is ready: |
| 8 | + |
| 9 | +1. **Check Node.js version** - Run `node --version` (should be v22+) |
| 10 | +2. **Check npm is available** - Run `npm --version` |
| 11 | +3. **Verify dependencies** - Run `npm install` if `node_modules` doesn't exist |
| 12 | +4. **Test the build** - Run `npm run build` to ensure compilation works |
| 13 | + |
| 14 | +## Step 1: Get Your Cloudflare Account ID |
| 15 | + |
| 16 | +Your Account ID uniquely identifies your Cloudflare account. |
| 17 | + |
| 18 | +**How to find it:** |
| 19 | + |
| 20 | +1. Log in to [Cloudflare Dashboard](https://dash.cloudflare.com) |
| 21 | +2. In the left sidebar, click **Workers & Pages** |
| 22 | +3. Look at the **right sidebar** - you'll see "Account details" |
| 23 | +4. Copy the **Account ID** (a 32-character hexadecimal string) |
| 24 | + |
| 25 | +**Example:** `a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6` |
| 26 | + |
| 27 | +**Store it safely** - you'll need this for GitHub Secrets. |
| 28 | + |
| 29 | +## Step 2: Create a Cloudflare API Token |
| 30 | + |
| 31 | +The API token allows GitHub Actions (or Wrangler) to deploy to your account. |
| 32 | + |
| 33 | +**How to create it:** |
| 34 | + |
| 35 | +1. Go to [Cloudflare API Tokens](https://dash.cloudflare.com/profile/api-tokens) |
| 36 | +2. Click **Create Token** |
| 37 | +3. Find **"Edit Cloudflare Workers"** template |
| 38 | +4. Click **Use Template** |
| 39 | + |
| 40 | +**Token permissions (pre-filled by template):** |
| 41 | + |
| 42 | +| Permission | Access | |
| 43 | +|------------|--------| |
| 44 | +| Account - Workers Scripts | Edit | |
| 45 | +| Account - Workers KV Storage | Edit | |
| 46 | +| Account - Workers R2 Storage | Edit | |
| 47 | +| Account - Workers Tail | Read | |
| 48 | +| Account - D1 | Edit | |
| 49 | +| Zone - Workers Routes | Edit | |
| 50 | + |
| 51 | +5. Under **Account Resources**, select your account (or "All accounts" if you have multiple) |
| 52 | +6. Under **Zone Resources**, select "All zones" (or specific zones if preferred) |
| 53 | +7. Click **Continue to summary** |
| 54 | +8. Click **Create Token** |
| 55 | +9. **IMPORTANT:** Copy the token immediately - it's only shown once! |
| 56 | + |
| 57 | +**Example token format:** `abcDEF123ghiJKL456mno...` (long string) |
| 58 | + |
| 59 | +## Step 3: Add Secrets to GitHub |
| 60 | + |
| 61 | +GitHub Secrets store your credentials securely and make them available to GitHub Actions. |
| 62 | + |
| 63 | +**How to add them:** |
| 64 | + |
| 65 | +1. Go to your GitHub repository |
| 66 | +2. Click **Settings** (tab at the top) |
| 67 | +3. In the left sidebar, click **Secrets and variables** → **Actions** |
| 68 | +4. Click **New repository secret** |
| 69 | + |
| 70 | +**Add these two secrets:** |
| 71 | + |
| 72 | +| Secret Name | Value | |
| 73 | +|-------------|-------| |
| 74 | +| `CLOUDFLARE_ACCOUNT_ID` | Your 32-character Account ID | |
| 75 | +| `CLOUDFLARE_API_TOKEN` | Your API token from Step 2 | |
| 76 | + |
| 77 | +**Verification:** |
| 78 | +- After adding, you should see both secrets listed (values are hidden) |
| 79 | +- The names must match exactly (case-sensitive) |
| 80 | + |
| 81 | +## Step 4: Local Development Setup (Optional) |
| 82 | + |
| 83 | +For local Wrangler commands (like `wrangler secret put`), authenticate: |
| 84 | + |
| 85 | +```bash |
| 86 | +# Interactive browser login |
| 87 | +npx wrangler login |
| 88 | + |
| 89 | +# Verify authentication |
| 90 | +npx wrangler whoami |
| 91 | +``` |
| 92 | + |
| 93 | +This creates a local auth token so you can run Wrangler commands directly. |
| 94 | + |
| 95 | +## Step 5: Verify Setup |
| 96 | + |
| 97 | +Let's test everything works: |
| 98 | + |
| 99 | +1. **Local development:** |
| 100 | + ```bash |
| 101 | + npm run dev |
| 102 | + # Should start at http://localhost:5173 |
| 103 | + ``` |
| 104 | + |
| 105 | +2. **Manual deployment test:** |
| 106 | + ```bash |
| 107 | + npm run deploy |
| 108 | + # Should deploy to *.workers.dev |
| 109 | + ``` |
| 110 | + |
| 111 | +3. **GitHub Actions test:** |
| 112 | + - Make a small change (e.g., add a comment to a file) |
| 113 | + - Commit and push to `main` branch |
| 114 | + - Go to your repo → Actions tab |
| 115 | + - Watch the deployment workflow run |
| 116 | + - Check for green checkmark (success) |
| 117 | + |
| 118 | +## Troubleshooting |
| 119 | + |
| 120 | +### "Authentication error" in GitHub Actions |
| 121 | + |
| 122 | +- Verify `CLOUDFLARE_API_TOKEN` is correct (re-create if unsure) |
| 123 | +- Ensure the token hasn't expired |
| 124 | +- Check token has "Edit Cloudflare Workers" permissions |
| 125 | + |
| 126 | +### "Account not found" error |
| 127 | + |
| 128 | +- Verify `CLOUDFLARE_ACCOUNT_ID` is correct |
| 129 | +- Ensure your token has access to that account |
| 130 | + |
| 131 | +### "Worker not found" when using custom domain |
| 132 | + |
| 133 | +- The Worker must be deployed before adding a custom domain |
| 134 | +- Ensure the name in `wrangler.jsonc` matches your Worker name |
| 135 | + |
| 136 | +### Local `wrangler` commands fail |
| 137 | + |
| 138 | +- Run `npx wrangler login` to re-authenticate |
| 139 | +- Ensure you're in the project directory |
| 140 | +- Check `wrangler.jsonc` exists and is valid JSON |
| 141 | + |
| 142 | +## Quick Reference |
| 143 | + |
| 144 | +| Item | Location | |
| 145 | +|------|----------| |
| 146 | +| Account ID | Dashboard → Workers & Pages → Right sidebar | |
| 147 | +| API Tokens | Dashboard → Profile → API Tokens | |
| 148 | +| GitHub Secrets | Repo → Settings → Secrets → Actions | |
| 149 | +| Wrangler Login | `npx wrangler login` | |
| 150 | +| Deploy Command | `npm run deploy` | |
| 151 | + |
| 152 | +## Next Steps |
| 153 | + |
| 154 | +Once setup is complete: |
| 155 | + |
| 156 | +1. Run `/new-project` to configure your project name and metadata |
| 157 | +2. Start building your application! |
| 158 | +3. Use `/add-ai-feature`, `/setup-database`, or other commands as needed |
| 159 | + |
| 160 | +## Links |
| 161 | + |
| 162 | +- [Cloudflare Dashboard](https://dash.cloudflare.com) |
| 163 | +- [API Tokens](https://dash.cloudflare.com/profile/api-tokens) |
| 164 | +- [Workers Documentation](https://developers.cloudflare.com/workers/) |
| 165 | +- [Wrangler Configuration](https://developers.cloudflare.com/workers/wrangler/configuration/) |
0 commit comments