Skip to content

Commit 2da2b8e

Browse files
Document CLOUDFLARE_CF_FETCH_ENABLED and CLOUDFLARE_CF_FETCH_PATH environment variables
Add documentation for two new environment variables that control cf.json fetching behavior in Miniflare: - CLOUDFLARE_CF_FETCH_ENABLED: disable cf.json fetching entirely - CLOUDFLARE_CF_FETCH_PATH: use a custom cache location for cf.json Updates both the system environment variables reference page and the Miniflare get-started guide. Related: cloudflare/workers-sdk#12469 Co-Authored-By: pbacondarwin@cloudflare.com <pete@bacondarwin.com>
1 parent ca540c2 commit 2da2b8e

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/content/docs/workers/testing/miniflare/get-started.mdx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ console.log("Listening on :5000");
193193
#### `Request#cf` Object
194194

195195
By default, Miniflare will fetch the `Request#cf` object from a trusted
196-
Cloudflare endpoint. You can disable this behaviour, using the `cf` option:
196+
Cloudflare endpoint and cache it to `node_modules/.mf/cf.json`. You can disable this behaviour, using the `cf` option:
197197

198198
```js
199199
const mf = new Miniflare({
@@ -209,6 +209,20 @@ const mf = new Miniflare({
209209
});
210210
```
211211

212+
You can also control this behaviour using [system environment variables](/workers/wrangler/system-environment-variables/), which is useful when you are not using the Miniflare API directly (for example, when running `wrangler dev`):
213+
214+
```sh
215+
# Disable cf fetching entirely (uses fallback data)
216+
export CLOUDFLARE_CF_FETCH_ENABLED=false
217+
npx wrangler dev
218+
219+
# Use a custom cache location for cf.json
220+
export CLOUDFLARE_CF_FETCH_PATH=/tmp/.cf-cache.json
221+
npx wrangler dev
222+
```
223+
224+
The explicit `cf` option in the Miniflare API takes precedence over both environment variables.
225+
212226
### HTTPS Server
213227

214228
To start an HTTPS server instead, set the `https` option. To use the [default shared self-signed certificate](https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare/src/http/cert.ts), set `https` to `true`:

src/content/docs/workers/wrangler/system-environment-variables.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ Wrangler supports the following environment variables:
9090

9191
* `WRANGLER_R2_SQL_AUTH_TOKEN` <Type text="string" /> <MetaInfo text="optional" />
9292
- API token used for executing queries with [R2 SQL](/r2-sql).
93+
94+
- `CLOUDFLARE_CF_FETCH_ENABLED` <Type text="string" /> <MetaInfo text="optional" />
95+
- Controls whether [Miniflare](/workers/testing/miniflare/) fetches the `cf.json` file containing [`Request.cf`](/workers/runtime-apis/request/#the-cf-property-requestinitcfproperties) properties from Cloudflare during local development. Set to `"false"` or `"0"` to disable fetching entirely and use fallback data. No `node_modules/.mf/cf.json` file will be created when disabled. Defaults to `"true"`. This is particularly useful for non-JavaScript projects (such as Rust or Go Workers) that do not want a `node_modules` directory created automatically. The explicit `cf` option in the [Miniflare API](/workers/testing/miniflare/get-started/#requestcf-object) takes precedence over this environment variable.
96+
97+
- `CLOUDFLARE_CF_FETCH_PATH` <Type text="string" /> <MetaInfo text="optional" />
98+
- Specifies a custom path for caching the `cf.json` file, overriding the default `node_modules/.mf/cf.json` location. This is useful for multi-project setups where you want a shared cache location, or for projects that want to store the cache outside of `node_modules`. The explicit `cf` option in the [Miniflare API](/workers/testing/miniflare/get-started/#requestcf-object) takes precedence over this environment variable, and `CLOUDFLARE_CF_FETCH_ENABLED=false` takes precedence over this variable.
99+
93100
## Example `.env` file
94101

95102
The following is an example `.env` file:
@@ -103,6 +110,7 @@ CLOUDFLARE_API_BASE_URL=https://api.cloudflare.com/client/v4
103110
WRANGLER_LOG=debug
104111
WRANGLER_LOG_PATH=../Desktop/my-logs/my-log-file.log
105112
WRANGLER_R2_SQL_AUTH_TOKEN=<YOUR_R2_API_TOKEN_VALUE>
113+
CLOUDFLARE_CF_FETCH_ENABLED=true
106114
```
107115

108116
## Deprecated global variables

0 commit comments

Comments
 (0)