secondsky/claude-skills / plugins/cloudflare-workers/skills/cloudflare-workers-frameworks
cloudflare-workers-frameworks
VerifiedFramework integration for Cloudflare Workers. Use when building with Hono, Remix, Next.js, Astro, SvelteKit, Qwik, or Nuxt on Workers. Covers routing, SSR, static assets, and edge deployment.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 5.6 KB |
| references/astro.md | markdown | 8.7 KB |
| references/hono.md | markdown | 14.8 KB |
| references/nextjs.md | markdown | 10.2 KB |
| references/nuxt.md | markdown | 9.8 KB |
| references/qwik.md | markdown | 10.3 KB |
| references/remix.md | markdown | 13.3 KB |
| references/sveltekit.md | markdown | 10.4 KB |
| templates/astro-page.astro | other | 7.9 KB |
| templates/hono-app.ts | script | 7.2 KB |
| templates/nextjs-route.ts | script | 10.3 KB |
| templates/nuxt-server.ts | script | 14.1 KB |
| templates/qwik-route.tsx | other | 12.6 KB |
| templates/remix-loader.tsx | other | 10.0 KB |
| templates/sveltekit-route.ts | script | 10.7 KB |
references/astro.md
View on GitHub# Astro on Cloudflare Workers
Content-focused framework with optional interactivity islands.
## Why Astro on Workers?
- **Zero JS by Default**: Ship minimal JavaScript
- **Islands Architecture**: Interactive components where needed
- **Content Collections**: Type-safe content management
- **SSR/SSG/Hybrid**: Choose per-route rendering
- **Multi-Framework**: Use React, Vue, Svelte components
## New Project Setup
```bash
# Create new Astro project
bun create astro@latest my-app
# Add Cloudflare adapter
cd my-app
bunx astro add cloudflare
# This adds:
# - @astrojs/cloudflare adapter
# - Updates astro.config.mjs
```
## Project Structure
```
my-app/
├── src/
│ ├── pages/
│ │ ├── index.astro # Home page
│ │ ├── about.astro # /about
│ │ ├── posts/
│ │ │ ├── index.astro # /posts
│ │ │ └── [slug].astro # /posts/:slug
│ │ └── api/
│ │ └── users.ts # /api/users
│ ├── components/
│ │ ├── Header.astro
│ │ └── Counter.tsx # React island
│ ├── layouts/
│ │ └── Base.astro
│ └── content/
│ └── posts/
│ └── hello.md
├── public/
├── astro.config.mjs
├── wrangler.jsonc
└── package.json
```
## Configuration
```javascript
// astro.config.mjs
import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';
import react from '@astrojs/react';
import tailwind from '@astrojs/tailwind';
export default defineConfig({
output: 'server', // or 'hybrid' for mixed SSR/SSG
adapter: cloudflare({
imageService: 'cloudflare',
platformProxy: {
enabled: true,
},
}),
integrations: [
react(),
tailwind(),
],
});
```
```jsonc
// wrangler.jsonc
{
"name": "astro-app",
"main": "./dist/_worker.js",
"compatibility_date": "2024-12-01",
"compatibility_flags": ["nodejs_compat"],
"assets": {
"directory": "./dist",
"binding": "ASSETS"
},
"d1_databases": [
{
"binding": "DB",
"database_name": "my-db",
"database_id": "xxx"
}
],
"kv_namespaces": [
{
"binding": "KV",
"id": "xxx"
}
]
}
```
## TypeScript Configuration
```typescript
// src/env.d.ts
/// <reference types="astro/client" />
interface Env {
DB: D1Database;
KV: KVNamespace;
R2: R2Bucket;
ENVIRONMENT: string;
}
type Runtime = import('@astrojs/cloudflare').Runtime<Env>;
declare namespace App {
interface Locals extends Runtime {}
}
```
## Accessing Cloudflare Bindings
```astro
---
// src/pages/index.astro
const runtime = Astro.locals.runtime;
const { DB, KV } = runtime.env;
interface Post {
id: number;
title: string;
content: string;
}
const { results: posts } = await DB.prepare(
'SELECT * FROM posts ORDER BY created_at DESC LIMIT 10'
).all<Post>();
---
<html>
<head>
<title>My Blog</title>
</head>
<body>
<h1>Latest Posts</h1>
<ul>
{posts.map((post) => (
<li>
<a href={`/posts/${post.id}`}>{post.title}</a>
</li>
))}
</ul>
</body>
</html>
```
## Dynamic Routes
```astro
---
// src/pages/posts/[slug].astro
import Layout from '../../layouts/Base.astro';
export const prerender = false; // SSR
const { slug } = Astro.params;
const { DB } = Astro.locals.runtime.env;
const post = await DB.prepare(
'SELECT * FROM posts WHERE slug = ?'
).bind(slug).first();
if (!post) {
return Astro.redirect('/404');
}
---
<Layout title={post.title}>
<article>
<h1>{post.title}</h1>
<div set:html={post.content} />
</article>
</Layout>
```
## API Routes
```typescript
// src/pages/api/users.ts
import type { APIRoute } from 'astro';
export const GET: APIRoute = async ({ locals }) => {
const { DB } = locals.runtime.env;
const { results } = await DB.prepare('SELECT * FROM users').all();
return new Response(JSON.stringify(results), {
status: 200,
headers: { 'Content-Type': 'application/json' },
});
};
export const POST: APIRoute = async ({ request, locals }) => {
const { DB } = locals.runtime.env;
const data = await request.json();
if (!data.name || !data.email) {
return new Response(
JSON.stringify({ error: 'Name and email required' }),
{ status: 400, headers: { 'Content-Type': 'application/json' } }
);
}
const result = await DB.prepare(
'INSERT INTO users (name, email) VALUES (?, ?) RETURNING *'
)
.bind(data.name, data.email)
.first();
return new Response(JSON.stringify(result), {
status: 201,
headers: { 'Content-Type': 'application/json' },
});
};
```
## Content Collections
```typescript
// src/content/config.ts
import { defineCollection, z } from 'astro:content';
const posts = defineCollection({
type: 'content',
schema: z.object({
title: z.string(),
description: z.string(),
publishDate: z.date(),
author: z.string(),
tags: z.array(z.string()).default([]),
draft: z.boolean().default(false),
}),
});
export const collections = { posts };
```
```markdown
---
# src/content/posts/hello-world.md
title: Hello World
description: My first blog post
publishDate: 2024-01-15
author: John Doe
tags: [astro, cloudflare]
---
# Hello World
This is my first blog post built with Astro on Cloudflare Workers!
```
```astro
---
// src/pages/blog/index.astro
import { getCollection } from 'astro:content';
import Layout from '../../layouts/Base.astro';
const posts = await getCollection('posts', ({ data }) => !data.draft);
posts.sort((a, b) => b.data.publishDate.valueOf() - a.data.publishDate.valueOf());
---
<Layout title="Blog">
<h1>Blog</h1>
<ul>
{posts.map((post) => (
<li>
<a href={`/blog/${post.slug}`}>{post.data.title}</a>
<time datetime={post.data.publishDate.toISOString()}>
{post.data.publishDate.toLocaleDateString()}
</time>
</li>
))}
</ul>
</Layout>
```
## Islands (Interactive Components)
```tsx
// src/components/Counter.tsx
import { useState } from 'react';
export default function Counter({ initial = 0 }: { initial?: number }) {
const [count, setCount] = useState(initial);
return (
<div>
<button onClick={() => setCount(c => c - 1)}>-</button>
<span>{count}</span>
<button onClick={() => setCount(c => c + 1)}>+</button>
</div>
);
}
```
```astro
---
// src/pages/interactive.astro
import Counter from '../components/Counter';
import Layout from '../layouts/Base.astro';
---
<Layout title="Interactive">
<h1>Interactive Page</h1>
<!-- Only hydrates on client load -->
<Counter client:load initial={5} />
<!-- Hydrates when visible -->
<Counter client:visible />
<!-- Hydrates on idle -->
<Counter client:idle />
<!-- Hydrates on media query -->
<Counter client:media="(max-width: 768px)" />
</Layout>
```
## Hybrid Rendering
```javascript
// astro.config.mjs
import { defineConfig } from 'astro/config';
import cloudflare from '@astrojs/cloudflare';
export default defineConfig({
output: 'hybrid', // Mix of static and SSR
adapter: cloudflare(),
});
```
```astro
---
// src/pages/static-page.astro
export const prerender = true; // Static at build time
---
<h1>This page is static</h1>
```
```astro
---
// src/pages/dynamic-page.astro
export const prerender = false; // SSR at runtime
const data = await fetch('https://api.example.com/data').then(r => r.json());
---
<h1>Dynamic: {data.title}</h1>
```
## Middleware
```typescript
// src/middleware.ts
import { defineMiddleware } from 'astro:middleware';
export const onRequest = defineMiddleware(async (context, next) => {
// Add timing header
const start = Date.now();
// Auth check
if (context.url.pathname.startsWith('/admin')) {
const token = context.cookies.get('token');
if (!token) {
return context.redirect('/login');
}
}
const response = await next();
// Add headers
response.headers.set('X-Response-Time', `${Date.now() - start}ms`);
return response;
});
```
## Caching
```astro
---
// src/pages/cached.astro
// Cache for 1 hour, serve stale for 1 day
Astro.response.headers.set(
'Cache-Control',
'public, max-age=3600, stale-while-revalidate=86400'
);
const data = await fetchData();
---
<h1>{data.title}</h1>
```
## Build and Deploy
```bash
# Development
bun run dev
# Build
bun run build
# Preview locally with Wrangler
bunx wrangler dev
# Deploy
bunx wrangler deploy
```
## Best Practices
1. **Prefer Static**: Use `prerender = true` for content pages
2. **Islands Sparingly**: Only hydrate what needs interactivity
3. **Content Collections**: Use for type-safe markdown/MDX
4. **Cache Headers**: Set Cache-Control on SSR pages
5. **Image Optimization**: Use Cloudflare Images service
6. **Type Bindings**: Define `Env` interface in `env.d.ts`
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 |