davila7/claude-code-templates / cli-tool/components/skills/development/cloudflare-deploy
cloudflare-deploy
FlaggedDeploy applications and infrastructure to Cloudflare using Workers, Pages, and related platform services. Use when the user asks to deploy, host, publish, or set up a project on Cloudflare.
references/pages-functions/api.md
View on GitHub# Function API
## EventContext
```typescript
interface EventContext<Env = any> {
request: Request; // Incoming request
functionPath: string; // Request path
waitUntil(promise: Promise<any>): void; // Background tasks (non-blocking)
passThroughOnException(): void; // Fallback to static on error
next(input?: Request | string, init?: RequestInit): Promise<Response>;
env: Env; // Bindings, vars, secrets
params: Record<string, string | string[]>; // Route params ([user] or [[catchall]])
data: any; // Middleware shared state
}
```
**TypeScript:** See [configuration.md](./configuration.md) for `wrangler types` setup
## Handlers
```typescript
// Generic (fallback for any method)
export async function onRequest(ctx: EventContext): Promise<Response> {
return new Response('Any method');
}
// Method-specific (takes precedence over generic)
export async function onRequestGet(ctx: EventContext): Promise<Response> {
return Response.json({ message: 'GET' });
}
export async function onRequestPost(ctx: EventContext): Promise<Response> {
const body = await ctx.request.json();
return Response.json({ received: body });
}
// Also: onRequestPut, onRequestPatch, onRequestDelete, onRequestHead, onRequestOptions
```
## Bindings Reference
| Binding Type | Interface | Config Key | Use Case |
|--------------|-----------|------------|----------|
| KV | `KVNamespace` | `kv_namespaces` | Key-value cache, sessions, config |
| D1 | `D1Database` | `d1_databases` | Relational data, SQL queries |
| R2 | `R2Bucket` | `r2_buckets` | Large files, user uploads, assets |
| Durable Objects | `DurableObjectNamespace` | `durable_objects.bindings` | Stateful coordination, websockets |
| Workers AI | `Ai` | `ai.binding` | LLM inference, embeddings |
| Vectorize | `VectorizeIndex` | `vectorize` | Vector search, embeddings |
| Service Binding | `Fetcher` | `services` | Worker-to-worker RPC |
| Analytics Engine | `AnalyticsEngineDataset` | `analytics_engine_datasets` | Event logging, metrics |
| Environment Vars | `string` | `vars` | Non-sensitive config |
See [configuration.md](./configuration.md) for wrangler.jsonc examples.
## Bindings
### KV
```typescript
interface Env { KV: KVNamespace; }
export const onRequest: PagesFunction<Env> = async (ctx) => {
await ctx.env.KV.put('key', 'value', { expirationTtl: 3600 });
const val = await ctx.env.KV.get('key', { type: 'json' });
const keys = await ctx.env.KV.list({ prefix: 'user:' });
return Response.json({ val });
};
```
### D1
```typescript
interface Env { DB: D1Database; }
export const onRequest: PagesFunction<Env> = async (ctx) => {
const user = await ctx.env.DB.prepare('SELECT * FROM users WHERE id = ?').bind(123).first();
return Response.json(user);
};
```
### R2
```typescript
interface Env { BUCKET: R2Bucket; }
export const onRequest: PagesFunction<Env> = async (ctx) => {
const obj = await ctx.env.BUCKET.get('file.txt');
if (!obj) return new Response('Not found', { status: 404 });
await ctx.env.BUCKET.put('file.txt', ctx.request.body);
return new Response(obj.body);
};
```
### Durable Objects
```typescript
interface Env { COUNTER: DurableObjectNamespace; }
export const onRequest: PagesFunction<Env> = async (ctx) => {
const stub = ctx.env.COUNTER.get(ctx.env.COUNTER.idFromName('global'));
return stub.fetch(ctx.request);
};
```
### Workers AI
```typescript
interface Env { AI: Ai; }
export const onRequest: PagesFunction<Env> = async (ctx) => {
const resp = await ctx.env.AI.run('@cf/meta/llama-3.1-8b-instruct', { prompt: 'Hello' });
return Response.json(resp);
};
```
### Service Bindings & Env Vars
```typescript
interface Env { AUTH: Fetcher; API_KEY: string; }
export const onRequest: PagesFunction<Env> = async (ctx) => {
// Service binding: forward to another Worker
return ctx.env.AUTH.fetch(ctx.request);
// Environment variable
return Response.json({ key: ctx.env.API_KEY });
};
```
## Advanced Mode (env.ASSETS)
When using `_worker.js`, access static assets via `env.ASSETS.fetch()`:
```typescript
interface Env { ASSETS: Fetcher; KV: KVNamespace; }
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const url = new URL(request.url);
if (url.pathname.startsWith('/api/')) {
return Response.json({ data: await env.KV.get('key') });
}
return env.ASSETS.fetch(request); // Fallback to static
}
} satisfies ExportedHandler<Env>;
```
**See also:** [configuration.md](./configuration.md) for TypeScript setup and wrangler.jsonc | [patterns.md](./patterns.md) for middleware and auth patterns
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| writing-skillsobra/superpowersUse when creating new skills, editing existing skills, or verifying skills work before deployment | Stars: 322k | Updated | Claude CodeCodex | Verified | Install |
| xlsxanthropics/skillsUse this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing .xlsx, .xlsm, .xltx, .csv, or .tsv file (e.g., adding columns, computing formulas, formatting, charting, cleaning messy data); create a new spreadsheet from scratch or from other data sources; or convert between tabular file formats. Trigger especially when the user references a spreadsheet file by name or path — even casually (like "the xlsx in my downloads") — and wants something done to it or produced from it. Also trigger for cleaning or restructuring messy tabular data files (malformed rows, misplaced headers, junk data) into proper spreadsheets. The deliverable must be a spreadsheet file. Do NOT trigger when the primary deliverable is a Word document, HTML report, standalone Python script, database pipeline, or Google Sheets API integration, even if tabular data is involved. | Stars: 197k | Updated | Claude CodeCodex | Verified | Install |
| shipping-and-launchaddyosmani/agent-skillsPrepares production launches. Use when preparing to deploy to production, or when asking what needs to be in place before shipping. Use when you need a pre-launch checklist, when setting up monitoring, when planning a staged rollout, or when you need a rollback strategy. | Stars: 119k | Updated | Claude CodeCodex | Verified | Install |
| childhoodthedotmack/claude-memBabysit a shipped release after merge, publication, or deployment. Verify published packages, production behavior, installed plugins, and late CI or user reports until the observation window is clean; use babysit for PR readiness before release. | Stars: 118k | Updated | Claude CodeCodex | Verified | Install |