cloudflarelisted
Install: claude install-skill Makiya1202/ai-agents-skills
# Cloudflare Platform
Build globally distributed applications on Cloudflare's edge network.
## Quick Start
```bash
# Install Wrangler CLI
npm install -g wrangler
# Login
wrangler login
# Create new Worker
wrangler init my-worker
# Deploy
wrangler deploy
```
## Workers
### Basic Worker
```typescript
// src/index.ts
export default {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const url = new URL(request.url);
if (url.pathname === '/api/hello') {
return Response.json({ message: 'Hello from the edge!' });
}
return new Response('Not Found', { status: 404 });
},
};
```
### wrangler.toml Configuration
```toml
name = "my-worker"
main = "src/index.ts"
compatibility_date = "2024-01-01"
[vars]
ENVIRONMENT = "production"
# KV Namespace
[[kv_namespaces]]
binding = "MY_KV"
id = "abc123"
# D1 Database
[[d1_databases]]
binding = "DB"
database_name = "my-database"
database_id = "def456"
# R2 Bucket
[[r2_buckets]]
binding = "BUCKET"
bucket_name = "my-bucket"
# AI
[ai]
binding = "AI"
# Durable Objects
[[durable_objects.bindings]]
name = "COUNTER"
class_name = "Counter"
[[migrations]]
tag = "v1"
new_classes = ["Counter"]
```
### Request Routing
```typescript
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const url = new URL(request.url);
const { pathname } = url;
// Router pattern
const routes: Record<string, () => Promise<Response>> = {
'/api/u