跳转到内容

绑定

使用 cf 的标准分产品字段;所有名称共享 Worker env namespace。

import { bindings, defineConfig } from "cf/config";
export default defineConfig({
worker: {
name: "app",
entrypoint: "src/index.ts",
compatibilityDate: "2026-09-08",
exports: {
Counter: {
type: "durable-object",
storage: "sqlite",
},
MyWorkflow: {
type: "workflow",
name: "flow",
},
},
env: {
KV: bindings.kv({ id: "<namespace-id>" }),
BUCKET: bindings.r2({ name: "files" }),
DB: bindings.d1({ id: "<database-id>", name: "app" }),
COUNTER: bindings.durableObject({ worker: "app", exportName: "Counter" }),
JOBS: bindings.queue({ name: "jobs" }),
FLOW: bindings.workflow({
name: "flow",
worker: "app",
exportName: "MyWorkflow",
}),
AUTH: bindings.worker({
worker: "auth-worker",
exportName: "AuthEntrypoint",
}),
LOADER: bindings.workerLoader(),
IMAGES: bindings.images(),
VERSION: bindings.versionMetadata(),
},
},
});

资源 ID 和名称必须解析到同一 account。声明的标准命令支持 provisioning 时由 cf 负责;server validation 会拒绝缺失、跨 account 或不支持的 binding。不要再添加已删除的通用 bindings 对象或 type/id/permissions 记录。operator 拥有的原生扩展继续使用 services 和 props,不增加公开 Binding 类型。见扩展。

配置变更后重新生成本地类型:

终端窗口
npm exec -- cf workers types

运行时细节:Runtime APIs · bindings。