agentsclimarketplace

Cloudflare workers expert

Skill findscripter/everything-skills/02-engineering/cloudflare-workers-expert

当在 Cloudflare 边缘部署 Serverless 函数、用 KV/D1/Durable Objects/R2 做边缘存储、或在边缘改写请求响应时使用;用 Wrangler 配置绑定、本地调试与部署,产出可上线的 Worker 代码与 wrangler.toml;不适用于传统 Node/Express、AWS Lambda、GCP Functions 或不涉及边缘特性的纯前端。触发词:Cloudflare Workers、Wrangler、Durable ObjectsFrom its SKILL.md

Install
npx -y skills add findscripter/everything-skills --skill cloudflare-workers-expert

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

2 things to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.
  • 1 stars1 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its file declares

Copied from the file, not written here

The file declares its own license as MIT. That is the author’s claim about this one file, and it is not the same thing as the license GitHub reports for the repository, which is listed with the other numbers below.

SKILL.md

4.8 KB, ~1.3k tokens by cl100k_base, as published. Nobody here has run it

何时使用

适用场景:

  • 把 Serverless 函数部署到 Cloudflare 边缘网络,靠近用户降低延迟。
  • 用 KV、D1(SQLite)、Durable Objects 或 R2 在边缘侧做数据存储与有状态协调。
  • 在边缘改写请求/响应:注入安全响应头、做边缘缓存、重定向。
  • 用 Cloudflare Pages + Workers 构建全栈应用。

不该用(负边界):

  • 跑在常驻服务器上的传统 Node.js/Express 应用。
  • 目标平台是 AWS Lambda 或 Google Cloud Functions(用对应技能)。
  • 不涉及边缘特性的普通前端开发。

关键约束:Workers 运行在 Web 标准 Fetch API 之上,没有 Node.js 全局对象(fspath 等需开启 Node 兼容模式才可用);免费版单 Worker 打包体积上限 1MB,CPU 时间和内存受限。

步骤

  1. 初始化与配置:用 wrangler.toml 管理配置,本地用 npx wrangler dev 调试。
  2. 声明绑定:所有绑定(KV、D1、secrets)在 wrangler.toml 中定义,运行时通过 fetch 处理器的 env 参数访问。
  3. 编写处理器:默认导出对象的 async fetch(request, env, ctx),返回标准 Response
  4. 选型存储:键值用 KV,关系型用 D1,强一致/高并发协调用 Durable Objects,大文件/对象用 R2。
  5. 后置任务:用 ctx.waitUntil() 处理响应发出后才需完成的非阻塞异步任务(日志、埋点)。
  6. 部署与观测:部署后用 wrangler tail 实时查看生产日志。

指令

  • Wrangler 生态:配置走 wrangler.toml,本地测试用 npx wrangler dev
  • Fetch API:使用 Web 标准 Fetch,不要依赖 Node 全局对象。
  • 绑定:在 wrangler.toml 定义后经 env 访问,不要硬编码密钥。
  • 冷启动:Workers 冷启动为 0ms,但要控制打包体积以满足免费版 1MB 限制。
  • Durable Objects:用于有状态协调和高并发场景。
  • 错误处理:非阻塞异步任务用 waitUntil(),避免阻塞响应。

示例

示例 1:带 KV 绑定的基础 Worker

export interface Env {
  MY_KV_NAMESPACE: KVNamespace;
}

export default {
  async fetch(
    request: Request,
    env: Env,
    ctx: ExecutionContext,
  ): Promise<Response> {
    const value = await env.MY_KV_NAMESPACE.get("my-key");
    if (!value) {
      return new Response("Not Found", { status: 404 });
    }
    return new Response(`Stored Value: ${value}`);
  },
};

示例 2:在边缘改写响应、注入安全头

export default {
  async fetch(request, env, ctx) {
    const response = await fetch(request);
    const newResponse = new Response(response.body, response);

    // 在边缘添加安全响应头
    newResponse.headers.set("X-Content-Type-Options", "nosniff");
    newResponse.headers.set(
      "Content-Security-Policy",
      "upgrade-insecure-requests",
    );

    return newResponse;
  },
};

注意事项

最佳实践:

  • env.VAR_NAME 读取密钥与环境变量,不要把敏感值写进代码。
  • 边缘重定向用 Response.redirect()
  • 生产实时排障用 wrangler tail
  • 不要引入大型库;Workers 内存和 CPU 时间受限。
  • 不要使用 Node.js 专属库(如 fspath),除非开启 Node 兼容模式。

常见问题:

  • 请求超出 CPU 时间限制:优化循环、减少 await 调用次数、把同步重计算移出请求/响应路径,并用 ctx.waitUntil() 承接不需阻塞响应的任务。

边界提醒:输出不能替代针对具体环境的验证、测试与专家评审;若缺少必要输入、权限、安全边界或成功标准,应先停下来澄清。

互见

  • 其他 Serverless/边缘平台技能(AWS Lambda、GCP Functions)按目标平台另行选用。
  • 前端构建与 Pages 集成可结合通用前端技能。

采编自 sickn33/antigravity-awesome-skills(MIT 许可)。

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Gives 0 of the 12 instructions most containers cloud skills give in ~1.3k tokens

Counted across 607 of the 657 authors here whose files we hold, read 2026-08-07

  • Run containers as a non-root userin 66 of 607, across 46 files
  • Use multi-stage buildsin 53 of 607, across 44 files
  • Use Promise.all for independent operationsin 47 of 607, across 13 files
  • Import directly instead of barrel filesin 46 of 607, across 12 files
  • Use ternary instead of AND for conditionalsin 45 of 607, across 12 files
  • Use Set or Map for O(1) lookupsin 42 of 607, across 10 files
  • Create a .dockerignore filein 41 of 607, across 31 files
  • Read individual rule files for detailsin 39 of 607, across 9 files
  • Copy dependency files before source codein 36 of 607, across 23 files
  • Authenticate server actions like API routesin 35 of 607, across 7 files
  • Use next/dynamic for heavy componentsin 34 of 607, across 9 files
  • Use React.cache for per-request deduplicationin 34 of 607, across 10 files

Said here and by no other author read

  • manage configuration in wrangler.toml
  • debug locally using wrangler dev
  • return a standard Response object
  • monitor production logs using wrangler tail
  • use env.VAR_NAME to read secrets
  • use Response.redirect for edge redirects

Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.

Keep looking

Skills are one crate of 326,835. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.