|
| 1 | +# Cloudflare Workers Deployment Guide |
| 2 | + |
| 3 | +This guide covers deploying FixFX Links to Cloudflare Workers. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +1. Cloudflare account at https://dash.cloudflare.com |
| 8 | +2. Workers enabled on your account |
| 9 | +3. Wrangler CLI installed globally: `npm install -g wrangler` |
| 10 | +4. Domain registered (for production deployment) |
| 11 | + |
| 12 | +## Setup Steps |
| 13 | + |
| 14 | +### 1. Authenticate with Cloudflare |
| 15 | + |
| 16 | +```bash |
| 17 | +wrangler login |
| 18 | +``` |
| 19 | + |
| 20 | +This will open a browser to grant Wrangler access to your Cloudflare account. |
| 21 | + |
| 22 | +### 2. Configure wrangler.toml |
| 23 | + |
| 24 | +Update the `wrangler.toml` file with your settings: |
| 25 | + |
| 26 | +```toml |
| 27 | +account_id = "your-account-id" # Found in Cloudflare dashboard |
| 28 | +``` |
| 29 | + |
| 30 | +For production with a custom domain: |
| 31 | + |
| 32 | +```toml |
| 33 | +[env.production] |
| 34 | +name = "fixfx-links-prod" |
| 35 | +routes = [ |
| 36 | + { pattern = "links.fixfx.wiki", zone_name = "fixfx.wiki" } |
| 37 | +] |
| 38 | +``` |
| 39 | + |
| 40 | +Replace `links.fixfx.wiki` and `fixfx.wiki` with your actual domain. |
| 41 | + |
| 42 | +### 3. Deploy to Workers |
| 43 | + |
| 44 | +Deploy to the default development environment: |
| 45 | + |
| 46 | +```bash |
| 47 | +bun run deploy |
| 48 | +``` |
| 49 | + |
| 50 | +Or deploy to production: |
| 51 | + |
| 52 | +```bash |
| 53 | +bun run deploy -e production |
| 54 | +``` |
| 55 | + |
| 56 | +The site will be available at: |
| 57 | +- Development: `https://fixfx-links.workers.dev` |
| 58 | +- Production: `https://links.fixfx.wiki` (if configured) |
| 59 | + |
| 60 | +## Environment Variables |
| 61 | + |
| 62 | +To set environment variables for your Workers: |
| 63 | + |
| 64 | +```bash |
| 65 | +wrangler secret put VARIABLE_NAME |
| 66 | +``` |
| 67 | + |
| 68 | +Then access in your code: |
| 69 | + |
| 70 | +```typescript |
| 71 | +const value = process.env.VARIABLE_NAME |
| 72 | +``` |
| 73 | + |
| 74 | +## Monitoring & Logs |
| 75 | + |
| 76 | +View real-time logs: |
| 77 | + |
| 78 | +```bash |
| 79 | +wrangler tail |
| 80 | +``` |
| 81 | + |
| 82 | +View in Cloudflare dashboard: |
| 83 | +1. Log in to https://dash.cloudflare.com |
| 84 | +2. Go to Workers > your-project > Logs |
| 85 | + |
| 86 | +## Custom Domain Setup |
| 87 | + |
| 88 | +To use a custom domain with Cloudflare Workers: |
| 89 | + |
| 90 | +1. Buy domain through Cloudflare or point nameservers to Cloudflare |
| 91 | +2. Update `wrangler.toml` with route configuration |
| 92 | +3. Redeploy: `bun run deploy -e production` |
| 93 | +4. Navigate to your domain in Cloudflare dashboard and verify Workers route |
| 94 | + |
| 95 | +## Performance Optimization |
| 96 | + |
| 97 | +Cloudflare Workers provides built-in optimizations: |
| 98 | +- Global edge network distribution |
| 99 | +- Automatic gzip compression |
| 100 | +- HTTP/2 and HTTP/3 support |
| 101 | +- Automatic HTTPS with free SSL |
| 102 | + |
| 103 | +## Troubleshooting |
| 104 | + |
| 105 | +### 401 Unauthorized |
| 106 | +Run `wrangler login` again to re-authenticate. |
| 107 | + |
| 108 | +### Build fails |
| 109 | +Ensure all dependencies are installed: |
| 110 | +```bash |
| 111 | +bun install |
| 112 | +``` |
| 113 | + |
| 114 | +### Site not loading |
| 115 | +Check Workers dashboard for errors: |
| 116 | +1. https://dash.cloudflare.com |
| 117 | +2. Workers > fixfx-links > Deployments |
| 118 | + |
| 119 | +### Custom domain not working |
| 120 | +Verify in Cloudflare dashboard: |
| 121 | +1. Domain is using Cloudflare nameservers |
| 122 | +2. Workers route matches your domain exactly |
| 123 | +3. SSL/TLS is set to "Full" or better |
| 124 | + |
| 125 | +## Rollback |
| 126 | + |
| 127 | +To rollback to a previous deployment: |
| 128 | + |
| 129 | +1. Go to Cloudflare dashboard |
| 130 | +2. Workers > fixfx-links > Deployments |
| 131 | +3. Click the deployment you want to rollback to |
| 132 | +4. Click "Rollback" |
| 133 | + |
| 134 | +## Local Testing |
| 135 | + |
| 136 | +Test the production build locally: |
| 137 | + |
| 138 | +```bash |
| 139 | +bun run build |
| 140 | +bun run start |
| 141 | +``` |
| 142 | + |
| 143 | +Then visit `http://localhost:3000` |
| 144 | + |
| 145 | +## Additional Resources |
| 146 | + |
| 147 | +- Cloudflare Workers Docs: https://developers.cloudflare.com/workers/ |
| 148 | +- Wrangler CLI Docs: https://developers.cloudflare.com/workers/wrangler/ |
| 149 | +- TanStack Start Deployment: https://tanstack.com/start/latest/docs/framework/react/guide/deploying |
0 commit comments