Skip to content

Setup Guide

Rahil Pirani edited this page May 16, 2026 · 3 revisions

Setup Guide

One-click deploy (recommended)

Deploy to Cloudflare

Click the Deploy to Cloudflare button in the README. Cloudflare will:

  • Fork the repo into your GitHub account
  • Provision a D1 database and Vectorize index
  • Prompt you to set an AUTH_TOKEN
  • Deploy the Worker automatically

During deployment

When you click Deploy, you'll see a configuration form. The only required input is:

AUTH_TOKEN — Choose one of these options:

  • Simple: Use a memorable phrase like coffee-lover-2026
  • Secure: Open your terminal, run openssl rand -base64 32, and paste the result
  • Online: Use this generator (opens in new tab) Save your token! You'll need it multiple times to connect AI clients.

After deployment

Find your Worker URL in Cloudflare Dashboard → Workers & Pages → second-brain. It looks like https://second-brain.<your-subdomain>.workers.dev.

That's it! The database schema auto-creates on your first request. No manual SQL or secret commands needed.

Test it

# Use the token you chose during deployment
curl -X POST https://<your-worker-url>/capture \
  -H "Authorization: Bearer coffee-lover-2026" \
  -H "Content-Type: application/json" \
  -d '{"content": "second brain is working", "source": "test"}'
# → {"ok":true,"id":"..."}

Then open https://<your-worker-url>/ to access the dashboard.


Manual setup (advanced) If you prefer to deploy from a local clone or need more control:

Prerequisites

  • Node.js 18+
  • A Cloudflare account (free tier works)
  • Wrangler CLI (installed via npm install)

Steps

# 1. Clone and install
git clone https://github.com/rahilp/second-brain-cloudflare.git
cd second-brain-cloudflare
npm install
 
# 2. Authenticate with Cloudflare
npx wrangler login
 
# 3. Create the D1 database
npm run db:create
# Copy the database_id from the output and paste it into wrangler.toml
 
# 4. Create the Vectorize index
npm run vectors:create
 
# 5. Set your auth token (schema will auto-create on first request)
openssl rand -base64 32  # Save this token!
npx wrangler secret put AUTH_TOKEN
 
# 6. Deploy
npm run deploy

Note: You no longer need to manually run the schema migration. The Worker will auto-create the table and indexes on first request.

Useful scripts

Script Description
npm run dev Start local dev server
npm run deploy Deploy to Cloudflare
npm run db:create Create the D1 database
npm run db:migrate Run schema against local D1 (optional)
npm run db:migrate:remote Run schema against remote D1 (optional)
npm run vectors:create Create the Vectorize index
---
Local development ```bash npm run dev ```

The schema will auto-create on your first request to the local Worker.

Vectorize and Workers AI are only available remotely. Embedding calls will fail gracefully during local development — entries will still be stored in D1 without vectors.

To test against your live remote resources:

npx wrangler dev --remote
---
Troubleshooting ### "Unauthorized" error

Make sure you're using the correct AUTH_TOKEN. If you forgot it:

  1. Go to Cloudflare Dashboard → Workers & Pages → second-brain → Settings → Variables
  2. Delete the old AUTH_TOKEN secret
  3. Add a new one with your desired token

Database table not found

The table should auto-create on first request. If you're getting errors, you can manually create it:

npm run db:migrate:remote

Need to reset your token

# For manual setup users
npx wrangler secret put AUTH_TOKEN
 
# For Deploy button users
# Go to Cloudflare Dashboard → Workers → Settings → Variables → Edit AUTH_TOKEN

Clone this wiki locally