Back to Skills

cloudflare-full-stack-integration

verified

React-to-Cloudflare Workers integration patterns with Hono, Clerk, D1. Use for frontend-backend connection, auth flow, or encountering CORS, 401 errors, token mismatches, race conditions.

View on GitHub

Marketplace

claude-skills

secondsky/claude-skills

Plugin

cloudflare-full-stack-integration

cloudflare

Repository

secondsky/claude-skills
28stars

plugins/cloudflare-full-stack-integration/skills/cloudflare-full-stack-integration/SKILL.md

Last Verified

January 24, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/secondsky/claude-skills/blob/main/plugins/cloudflare-full-stack-integration/skills/cloudflare-full-stack-integration/SKILL.md -a claude-code --skill cloudflare-full-stack-integration

Installation paths:

Claude
.claude/skills/cloudflare-full-stack-integration/
Powered by add-skill CLI

Instructions

# Cloudflare Full-Stack Integration Patterns

Production-tested patterns for React + Cloudflare Workers + Hono + Clerk authentication.

## When to Use This Skill

Use this skill when you need to:

- Connect a React frontend to a Cloudflare Worker backend
- Implement authentication with Clerk in a full-stack app
- Set up API calls that automatically include auth tokens
- Fix CORS errors between frontend and backend
- Prevent race conditions with auth loading
- Configure environment variables correctly
- Set up D1 database access from API routes
- Create protected routes that require authentication

## What This Skill Provides

### Templates

**Frontend** (`templates/frontend/`):
- `lib/api-client.ts` - Fetch wrapper with automatic token attachment
- `components/ProtectedRoute.tsx` - Auth gate pattern with loading states

**Backend** (`templates/backend/`):
- `middleware/cors.ts` - CORS configuration for dev and production
- `middleware/auth.ts` - JWT verification with Clerk
- `routes/api.ts` - Example API routes with all patterns integrated

**Config** (`templates/config/`):
- `wrangler.jsonc` - Complete Workers configuration with bindings
- `.dev.vars.example` - Environment variables setup
- `vite.config.ts` - Cloudflare Vite plugin configuration

**References** (`references/`):
- `common-race-conditions.md` - Complete guide to auth loading issues

## Critical Architectural Insights

### 1. @cloudflare/vite-plugin Runs on SAME Port

**Key Insight**: The Worker and frontend run on the SAME port during development.

```typescript
// ✅ CORRECT: Use relative URLs
fetch('/api/data')

// ❌ WRONG: Don't use absolute URLs or proxy
fetch('http://localhost:8787/api/data')
```

**Why**: The Vite plugin runs your Worker using workerd directly in the dev server. No proxy needed!

### 2. CORS Must Be Applied BEFORE Routes

```typescript
// ✅ CORRECT ORDER
app.use('/api/*', cors())
app.post('/api/data', handler)

// ❌ WRONG ORDER - Will cause CORS errors
app.post('/api/data', hand

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
9582 chars