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/miniflare/api.md
View on GitHub# Programmatic API
## Miniflare Class
```typescript
class Miniflare {
constructor(options: MiniflareOptions);
// Lifecycle
ready: Promise<URL>; // Resolves when server ready, returns URL
dispose(): Promise<void>; // Cleanup resources
setOptions(options: MiniflareOptions): Promise<void>; // Reload config
// Event dispatching
dispatchFetch(url: string | URL | Request, init?: RequestInit): Promise<Response>;
getWorker(name?: string): Promise<Worker>;
// Bindings access
getBindings<Bindings = Record<string, unknown>>(name?: string): Promise<Bindings>;
getCf(name?: string): Promise<IncomingRequestCfProperties | undefined>;
getKVNamespace(name: string): Promise<KVNamespace>;
getR2Bucket(name: string): Promise<R2Bucket>;
getDurableObjectNamespace(name: string): Promise<DurableObjectNamespace>;
getDurableObjectStorage(id: DurableObjectId): Promise<DurableObjectStorage>;
getD1Database(name: string): Promise<D1Database>;
getCaches(): Promise<CacheStorage>;
getQueueProducer(name: string): Promise<QueueProducer>;
// Debugging
getInspectorURL(): Promise<URL>; // Chrome DevTools inspector URL
}
```
## Event Dispatching
**Fetch (no HTTP server):**
```js
const res = await mf.dispatchFetch("http://localhost:8787/path", {
method: "POST",
headers: { "Authorization": "Bearer token" },
body: JSON.stringify({ data: "value" }),
});
```
**Custom Host routing:**
```js
const res = await mf.dispatchFetch("http://localhost:8787/", {
headers: { "Host": "api.example.com" },
});
```
**Scheduled:**
```js
const worker = await mf.getWorker();
const result = await worker.scheduled({ cron: "30 * * * *" });
// result: { outcome: "ok", noRetry: false }
```
**Queue:**
```js
const worker = await mf.getWorker();
const result = await worker.queue("queue-name", [
{ id: "msg1", timestamp: new Date(), body: "data", attempts: 1 },
]);
// result: { outcome: "ok", retryAll: false, ackAll: false, ... }
```
## Bindings Access
**Environment variables:**
```js
// Basic usage
const bindings = await mf.getBindings();
console.log(bindings.SECRET_KEY);
// With type safety (recommended):
interface Env {
SECRET_KEY: string;
API_URL: string;
KV: KVNamespace;
}
const env = await mf.getBindings<Env>();
env.SECRET_KEY; // string (typed!)
env.KV.get("key"); // KVNamespace methods available
```
**Request.cf object:**
```js
const cf = await mf.getCf();
console.log(cf?.colo); // "DFW"
console.log(cf?.country); // "US"
```
**KV:**
```js
const ns = await mf.getKVNamespace("TEST_NAMESPACE");
await ns.put("key", "value");
const value = await ns.get("key");
```
**R2:**
```js
const bucket = await mf.getR2Bucket("BUCKET");
await bucket.put("file.txt", "content");
const object = await bucket.get("file.txt");
```
**Durable Objects:**
```js
const ns = await mf.getDurableObjectNamespace("COUNTER");
const id = ns.idFromName("test");
const stub = ns.get(id);
const res = await stub.fetch("http://localhost/");
// Access storage directly:
const storage = await mf.getDurableObjectStorage(id);
await storage.put("key", "value");
```
**D1:**
```js
const db = await mf.getD1Database("DB");
await db.exec(`CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)`);
await db.prepare("INSERT INTO users (name) VALUES (?)").bind("Alice").run();
```
**Cache:**
```js
const caches = await mf.getCaches();
const defaultCache = caches.default;
await defaultCache.put("http://example.com", new Response("cached"));
```
**Queue producer:**
```js
const producer = await mf.getQueueProducer("QUEUE");
await producer.send({ body: "message data" });
```
## Lifecycle
**Reload:**
```js
await mf.setOptions({
scriptPath: "worker.js",
bindings: { VERSION: "2.0" },
});
```
**Watch (manual):**
```js
import { watch } from "fs";
const config = { scriptPath: "worker.js" };
const mf = new Miniflare(config);
watch("worker.js", async () => {
console.log("Reloading...");
await mf.setOptions(config);
});
```
**Cleanup:**
```js
await mf.dispose();
```
## Debugging
**Inspector URL for DevTools:**
```js
const url = await mf.getInspectorURL();
console.log(`DevTools: ${url}`);
// Open in Chrome DevTools for breakpoints, profiling
```
**Wait for server ready:**
```js
const mf = new Miniflare({ scriptPath: "worker.js" });
const url = await mf.ready; // Promise<URL>
console.log(`Server running at ${url}`); // http://127.0.0.1:8787
// Note: dispatchFetch() waits automatically, no need to await ready
const res = await mf.dispatchFetch("http://localhost/"); // Works immediately
```
See [configuration.md](./configuration.md) for all constructor options.
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 |