Configuration (17)·续1
defineRecord<string, string>optional- A map of values to substitute when deploying your Worker.
- If you're using the Cloudflare Vite plugin,
defineis replaced by Vite'sdefine↗︎. varsobjectoptional- A map of environment variables to set when deploying your Worker. Refer to Environment variables.
durable_objectsobjectoptional- A list of Durable Objects that your Worker should be bound to. Refer to Durable Objects.
kv_namespacesobjectoptional- A list of KV namespaces that your Worker should be bound to. Refer to KV namespaces.
r2_bucketsobjectoptional- A list of R2 buckets that your Worker should be bound to. Refer to R2 buckets.
analyticsobjectoptional- An Analytics SQL binding. Refer to Analytics SQL.
ai_search_namespacesobjectoptional- A list of AI Search namespaces that your Worker should be bound to. Refer to AI Search namespaces.
ai_searchobjectoptional- A list of AI Search instance bindings bound directly to pre-existing instances in the default namespace. Refer to AI Search instances.
vectorizeobjectoptional- A list of Vectorize indexes that your Worker should be bound to. Refer to Vectorize indexes.
servicesobjectoptional- A list of service bindings that your Worker should be bound to. Refer to service bindings.
queuesobjectoptional- A list of Queue producers and consumers that your Worker should be bound to. Refer to Queues.
workflowsobjectoptional- A list of Workflows that your Worker should be bound to. Refer to Workflows.
tail_consumersobjectoptional- A list of the Tail Workers your Worker sends data to. Refer to Tail Workers.
secretsobjectoptional- Declares the secret names your Worker requires. Used for validation during local development and deploy, and as the source of truth for type generation. Refer to Secrets.
requiredstring[]optional — A list of secret names that must be set to deploy your Worker.secrets_store_secretsobjectoptional- A list of Secrets Store bindings that your worker should be bound to. Refer to Secrets Store.
Types of routes
There are three types of routes: Custom Domains, routes, and workers.dev.
Custom Domains
Custom Domains allow you to connect your Worker to a domain or subdomain, without having to make changes to your DNS settings or perform any certificate management.
patternstringrequired- The pattern that your Worker should be run on, for example,
"example.com". custom_domainbooleanoptional- Whether the Worker should be on a Custom Domain as opposed to a route. Defaults to
false.
Example:
{
"routes": [
{
"pattern": "shop.example.com",
"custom_domain": true,
},
],
}
[[routes]]
pattern = "shop.example.com"
custom_domain = true
Routes
Routes allow users to map a URL pattern to a Worker. A route can be configured as a zone ID route, a zone name route, or a simple route.
Zone ID route
patternstringrequired- The pattern that your Worker can be run on, for example,
"example.com/*". zone_idstringrequired- The ID of the zone that your
patternis associated with. Refer to Find zone and account IDs.
Example:
{
"routes": [
{
"pattern": "subdomain.example.com/*",
"zone_id": "<YOUR_ZONE_ID>",
},
],
}
[[routes]]
pattern = "subdomain.example.com/*"
zone_id = "<YOUR_ZONE_ID>"
Zone name route
patternstringrequired- The pattern that your Worker should be run on, for example,
"example.com/*". zone_namestringrequired- The name of the zone that your
patternis associated with. If you are using API tokens, this will require theAccountscope.
Example:
{
"routes": [
{
"pattern": "subdomain.example.com/*",
"zone_name": "example.com",
},
],
}
[[routes]]
pattern = "subdomain.example.com/*"
zone_name = "example.com"
Simple route
This is a simple route that only requires a pattern.
Example:
{
"route": "example.com/*",
}
route = "example.com/*"
workers.dev
Cloudflare Workers accounts come with a workers.dev subdomain that is configurable in the Cloudflare dashboard.
workers_devbooleanoptional- Whether the Worker runs on a custom
workers.devaccount subdomain. Defaults totruewhen the configuration has norouteorroutes, andfalseotherwise. To keep theworkers.devURL alongside routes, setworkers_devtotrue. For more information, refer toworkers.dev.
{
"workers_dev": false,
}
workers_dev = false
Triggers
Triggers allow you to define the cron expression to invoke your Worker's scheduled function. Refer to Supported cron expressions.
cronsstring[]required- An array of
cronexpressions. - To disable a Cron Trigger, set
crons = []. Commenting out thecronskey will not disable a Cron Trigger.
Example:
{
"triggers": {
"crons": ["* * * * *"],
},
}
[triggers]
crons = [ "* * * * *" ]
Observability
The Observability setting allows you to automatically ingest, store, filter, and analyze logging data emitted from Cloudflare Workers directly from your Cloudflare Worker's dashboard.
enabledbooleanoptional- Shorthand for
logs.enabled. When set totrueon a Worker, logs for the Worker are persisted. Defaults totruefor all new Workers. logs.enabledbooleanoptional- Whether logs for the Worker are persisted.
head_sampling_ratenumberoptional- A number between 0 and 1, where 0 indicates zero out of one hundred requests are logged, and 1 indicates every request is logged. If
head_sampling_rateis unspecified, it is configured to a default value of 1 (100%). Read more about head-based sampling.
Example:
{
"observability": {
"enabled": true,
"head_sampling_rate": 0.1, // 10% of requests are logged
},
}
[observability]
enabled = true
head_sampling_rate = 0.1
Issues
Requires Wrangler 4.134.0 or later.
Set observability.issues.enabled to true to detect and group production failures for a Worker. Set it to false and deploy the Worker to stop detecting new failures. Refer to Workers Issues for supported signals, retention, and behavior.
{
"$schema": "./node_modules/wrangler/config-schema.json",
"observability": {
"issues": {
"enabled": true
}
}
}
[observability.issues]
enabled = true
Custom builds
Note
Not applicable if you're using the Cloudflare Vite plugin.
You can configure a custom build step that will be run before your Worker is deployed. Refer to Custom builds.
commandstringoptional- The command used to build your Worker. On Linux and macOS, the command is executed in the
shshell and thecmdshell for Windows. The&&and||shell operators may be used. cwdstringoptional- The directory in which the command is executed.
watch_dirstring | string[]optional- The directory to watch for changes while using
wrangler dev. Defaults to the current working directory.
Example:
{
"build": {
"command": "npm run build",
"cwd": "build_cwd",
"watch_dir": "build_watch_dir",
},
}
[build]
command = "npm run build"
cwd = "build_cwd"
watch_dir = "build_watch_dir"
Limits
You can impose limits on your Worker's behavior at runtime. Limits are only supported for the Standard Usage Model. Limits are only enforced when deployed to Cloudflare's network, not in local development. The CPU limit can be set to a maximum of 300,000 milliseconds (5 minutes).
Each isolate has some built-in flexibility to allow for cases where your Worker infrequently runs over the configured limit. If your Worker starts hitting the limit consistently, its execution will be terminated according to the limit configured.
cpu_msnumberoptional- The maximum CPU time allowed per invocation, in milliseconds.
subrequestsnumberoptional- The maximum number of subrequests allowed per invocation. This value defaults to 50 for free accounts and 10,000 for paid accounts. The free account maximum is 50 and the paid account maximum is 10,000,000. Refer to subrequest limits for more information.
Example:
{
"limits": {
"cpu_ms": 100,
"subrequests": 150,
},
}
[limits]
cpu_ms = 100
subrequests = 150
Bindings
Browser Run
The Workers Browser Run API allows developers to programmatically control and interact with a headless browser instance and create automation flows for their applications and products.
A browser binding will provide your Worker with an authenticated endpoint to interact with a dedicated Chromium browser instance.
bindingstringrequired- The binding name used to refer to the browser binding. The value (string) you set will be used to reference this headless browser in your Worker. The binding must be a valid JavaScript variable name ↗︎. For example,
binding = "HEAD_LESS"orbinding = "simulatedBrowser"would both be valid names for the binding.
Example:
{
"browser": {
"binding": "<BINDING_NAME>",
},
}
[browser]
binding = "<BINDING_NAME>"
D1 databases
D1 is Cloudflare's serverless SQL database. A Worker can query a D1 database (or databases) by creating a binding to each database for D1 Workers Binding API.
To bind D1 databases to your Worker, assign an array of the below object to the [[d1_databases]] key.
bindingstringrequired- The binding name used to refer to the D1 database. The value (string) you set will be used to reference this database in your Worker. The binding must be a valid JavaScript variable name ↗︎. For example,
binding = "MY_DB"orbinding = "productionDB"would both be valid names for the binding. database_namestringrequired- The name of the database. This is a human-readable name that allows you to distinguish between different databases, and is set when you first create the database.
database_idstringrequired- The ID of the database. The database ID is available when you first use
wrangler d1 createor when you callwrangler d1 list, and uniquely identifies your database. preview_database_idstringoptional- The preview ID of this D1 database. If provided,
wrangler devuses this ID. Otherwise, it usesdatabase_id. This option is recommended when usingwrangler dev --remoteto avoid using your production database. migrations_dirstringoptional- The migration directory containing the migration files. By default,
wrangler d1 migrations createcreates a folder namedmigrations. You can usemigrations_dirto specify a different folder containing the migration files (for example, if you have a mono-repo setup, and want to use a single D1 instance across your apps/packages). - For more information, refer to D1 Wrangler
migrationscommands and D1 migrations. migrations_patternstringoptional- A glob pattern (relative to your Wrangler config file) used to discover migration files. Defaults to
migrations/*.sql. - Use this to opt in to nested layouts produced by ORMs like Drizzle (for example,
migrations/*/migration.sql). - When
migrations_patternis set,migrations_dirmust also be set, andmigrations_patternmust start with whatevermigrations_diris set to. Each migration is recorded in the migrations table as a path relative tomigrations_dir.
Note
When using Wrangler in the default local development mode, files will be written to local storage instead of the preview or production database. Refer to Local development for more details.
Example:
{
"d1_databases": [
{
"binding": "<BINDING_NAME>",
"database_name": "<DATABASE_NAME>",
"database_id": "<DATABASE_ID>",
},
],
}
[[d1_databases]]
binding = "<BINDING_NAME>"
database_name = "<DATABASE_NAME>"
database_id = "<DATABASE_ID>"
Dispatch namespace bindings (Workers for Platforms)
Dispatch namespace bindings allow for communication between a dynamic dispatch Worker and a dispatch namespace. Dispatch namespace bindings are used in Workers for Platforms. Workers for Platforms helps you deploy serverless functions programmatically on behalf of your customers.
bindingstringrequired- The binding name. The value (string) you set will be used to reference this database in your Worker. The binding must be a valid JavaScript variable name ↗︎. For example,
binding = "MY_NAMESPACE"orbinding = "productionNamespace"would both be valid names for the binding. namespacestringrequired- The name of the dispatch namespace.
outboundobjectoptionalservicestringrequired The name of the outbound Worker to bind to.parametersarray optional A list of parameters to pass data from your dynamic dispatch Worker to the outbound Worker.
{
"dispatch_namespaces": [
{
"binding": "<BINDING_NAME>",
"namespace": "<NAMESPACE_NAME>",
"outbound": {
"service": "<WORKER_NAME>",
"parameters": ["params_object"],
},
},
],
}
[[dispatch_namespaces]]
binding = "<BINDING_NAME>"
namespace = "<NAMESPACE_NAME>"
[dispatch_namespaces.outbound]
service = "<WORKER_NAME>"
parameters = [ "params_object" ]
Durable Objects
Durable Objects provide low-latency coordination and consistent storage for the Workers platform.
To bind Durable Objects to your Worker, assign an array of the below object to the durable_objects.bindings key.
