Skip to content

Commit 003f739

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 c930838 commit 003f739

2 files changed

Lines changed: 21 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ Other entry types include:
124124
- `pages-deploy` - Written by `wrangler pages deploy` with Pages deployment details
125125
- `command-failed` - Written when a command fails, including error code and message
126126

127+
- `CLOUDFLARE_CF_FETCH_ENABLED` <Type text="string" /> <MetaInfo text="optional" />
128+
- 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.
129+
130+
- `CLOUDFLARE_CF_FETCH_PATH` <Type text="string" /> <MetaInfo text="optional" />
131+
- 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.
127132
## Example `.env` file
128133

129134
The following is an example `.env` file:
@@ -137,6 +142,7 @@ CLOUDFLARE_API_BASE_URL=https://api.cloudflare.com/client/v4
137142
WRANGLER_LOG=debug
138143
WRANGLER_LOG_PATH=../Desktop/my-logs/my-log-file.log
139144
WRANGLER_R2_SQL_AUTH_TOKEN=<YOUR_R2_API_TOKEN_VALUE>
145+
CLOUDFLARE_CF_FETCH_ENABLED=true
140146
```
141147

142148
## Deprecated global variables

0 commit comments

Comments
 (0)