Cloudflare Setup Guide
Complete guide for setting up Cloudflare services for the freeAIhashtags.com monorepo.
Overview
freeAIhashtags.com uses the following Cloudflare services:
- Cloudflare Workers: Frontend hosting (
apps/webvia OpenNext) - Cloudflare Workers: API Gateway (
apps/api) - Cloudflare KV: API caching and rate limiting
- Cloudflare Turnstile: CAPTCHA alternative
1. Create a Cloudflare Account
- Go to https://dash.cloudflare.com/sign-up
- Enter your email and create a password
- Click Sign Up
- Verify your email address if requested
2. Create Pages Project for Frontend
- Log in to the Cloudflare Dashboard
- In the sidebar, click Workers & Pages
- Click Create application
- Select the Pages tab
- Click Create using Direct Upload
- Why? We have GitHub Actions workflows that give us more control
- Do not select "Connect to Git"
- Project Name: Enter
faiht-frontend - Click Create Project
[!NOTE] Both
mainandsandboxbranches deploy to the same project.
- Production (
main): Uses production environment variables- Sandbox (
sandbox): Uses sandbox environment variables
3. Generate API Token
You need an API token to allow GitHub Actions to deploy to Cloudflare.
- Go to User Profile > API Tokens
- Click Create Token
- Use the Edit Cloudflare Workers template or Create Custom Token
- Permissions:
- Account > Cloudflare Pages > Edit
- Account > Workers Scripts > Edit
- Account > Workers KV Storage > Edit
- Account Resources: Include All accounts (or select your specific account)
- Click Continue to summary → Create Token
- COPY THIS TOKEN IMMEDIATELY (you won't see it again)
4. Get Your Account ID
- Go to your Cloudflare Dashboard
- The URL will look like:
https://dash.cloudflare.com/<ACCOUNT_ID>/... - Copy the
<ACCOUNT_ID>string from the URL
Alternative: Click on your account name in the top right and look for "Account ID"
5. Configure Cloudflare Turnstile
Turnstile is Cloudflare's CAPTCHA alternative (free and unlimited).
- Go to the Cloudflare Dashboard
- In the sidebar, click Turnstile
- Click Add Widget (or Add Site)
- Widget Name:
faiht-frontend - Domain:
- Add your production domain:
freeaihashtags.com - Add sandbox domain:
faiht-frontend.adeel-zain-work.workers.dev - Add
localhostfor local testing
- Add your production domain:
- Widget Mode: Select Managed (Recommended)
- Click Create
- Copy Keys:
- Site Key: Public (can be embedded in frontend)
- Secret Key: Private (for server-side verification)
6. Setup KV Namespaces
KV namespaces are required for the API Gateway's caching and rate limiting.
See: KV Namespace Setup for detailed instructions.
Quick summary:
cd apps/api
# Create sandbox namespace
wrangler kv:namespace create "FAIHT_CACHE" --env sandbox
# Create production namespace
wrangler kv:namespace create "FAIHT_CACHE"
# Add IDs to GitHub Secrets
7. Configure GitHub Secrets & Variables
Variables (Non-Sensitive)
Go to: Repository → Settings → Secrets and variables → Actions → Variables
Click New repository variable for each:
| Variable Name | Value |
|---|---|
CLOUDFLARE_ACCOUNT_ID | <your-account-id> (from Step 4) |
Secrets (Sensitive)
Go to: Repository → Settings → Secrets and variables → Actions → Secrets
Click New repository secret for each:
| Secret Name | Value | Source |
|---|---|---|
CLOUDFLARE_API_TOKEN | <your-api-token> | Step 3 |
SANDBOX_KV_NAMESPACE_ID | <namespace-id> | Step 6 |
PROD_KV_NAMESPACE_ID | <namespace-id> | Step 6 |
For Turnstile (per environment):
SANDBOX_NEXT_PUBLIC_TURNSTILE_SITE_KEYSANDBOX_TURNSTILE_SECRET_KEYPROD_NEXT_PUBLIC_TURNSTILE_SITE_KEYPROD_TURNSTILE_SECRET_KEY
8. Update Supabase CORS
Add your Cloudflare Pages URLs to Supabase CORS configuration:
- Go to Supabase Dashboard
- Navigate to Settings > Edge Functions
- Add or update
ACCESS_CONTROL_ALLOW_ORIGIN:http://localhost:3000,https://freeaihashtags.com,https://faiht-frontend.adeel-zain-work.workers.dev
[!IMPORTANT] Whenever you deploy to a new URL (like a preview deployment), add it to the CORS list.
9. Verify Setup
Test Pages Deployment
cd apps/web
pnpm build
npx wrangler pages deploy out --project-name=faiht-frontend --branch=sandbox
Test Worker Deployment
cd apps/api
npx wrangler deploy
Test KV Access
cd apps/api
wrangler kv:key put --binding=FAIHT_CACHE "test-key" "test-value" --env sandbox
wrangler kv:key get --binding=FAIHT_CACHE "test-key" --env sandbox