Skip to content

Workers

在本机运行 Cloudflare 模块 Worker。ocd 启动锁定版本的 workerd。不提供全球边缘网络、workers.dev 或 Cloudflare 控制台。

可以:

  • 使用 oc run 部署模块 Worker(export default { fetch }
  • 绑定 KV、R2、D1、Durable Objects、Queues、Workflows 以及其他 Worker
  • 使用 UTC cron 触发 scheduled()
  • 在同一份部署中提供静态资源
ts
export default {
  fetch(request: Request, env: Env): Response {
    return Response.json({
      message: env.GREETING,
      pathname: new URL(request.url).pathname,
    });
  },
} satisfies ExportedHandler<Env>;

仓库示例为 examples/hello-worker/。针对已运行的 ocd 部署(默认 origin http://127.0.0.1:8787):

sh
bun run oc run --config examples/hello-worker/open-compute.json --ocd <ocd-path>

兼容性

主题Cloudflareopen-compute
模块 Worker(export default { fetch }提供提供
isolate、env 绑定、fetch / scheduled / queue提供提供
Cache API、WebSocket hibernation、cloudflare:socketsnode:提供提供,与 Workers runtime APIs 一致
全球 Anycast / workers.dev / 自定义域名产品提供不提供
项目文件wrangler.jsoncopen-compute.json(未知字段将被拒绝)
项目 JSON 中的 compatibilityDate提供不允许;由 runtime 锁定(当前 2026-08-30
部署状态Cloudflare 控制面本机 SQLite;ocd 监督当前 workerd 进程

本节

若尚未运行 ocd,见 ocd 安装