diff --git a/src/content/docs/workers/testing/miniflare/get-started.mdx b/src/content/docs/workers/testing/miniflare/get-started.mdx index ca369857074e141..50c7d84a1402a59 100644 --- a/src/content/docs/workers/testing/miniflare/get-started.mdx +++ b/src/content/docs/workers/testing/miniflare/get-started.mdx @@ -193,7 +193,7 @@ console.log("Listening on :5000"); #### `Request#cf` Object By default, Miniflare will fetch the `Request#cf` object from a trusted -Cloudflare endpoint. You can disable this behaviour, using the `cf` option: +Cloudflare endpoint and cache it to `node_modules/.mf/cf.json`. You can disable this behaviour, using the `cf` option: ```js const mf = new Miniflare({ @@ -209,6 +209,20 @@ const mf = new Miniflare({ }); ``` +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`): + +```sh +# Disable cf fetching entirely (uses fallback data) +export CLOUDFLARE_CF_FETCH_ENABLED=false +npx wrangler dev + +# Use a custom cache location for cf.json +export CLOUDFLARE_CF_FETCH_PATH=/tmp/.cf-cache.json +npx wrangler dev +``` + +The explicit `cf` option in the Miniflare API takes precedence over both environment variables. + ### HTTPS Server 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`: diff --git a/src/content/docs/workers/wrangler/system-environment-variables.mdx b/src/content/docs/workers/wrangler/system-environment-variables.mdx index 923c52219efa142..8adf620d170ac90 100644 --- a/src/content/docs/workers/wrangler/system-environment-variables.mdx +++ b/src/content/docs/workers/wrangler/system-environment-variables.mdx @@ -77,16 +77,16 @@ Wrangler supports the following environment variables: - `FORCE_COLOR` - By setting this to `0`, you can disable Wrangler's colorised output, which makes it easier to read with some terminal setups. For example, `FORCE_COLOR=0`. -* `WRANGLER_HTTPS_KEY_PATH` +- `WRANGLER_HTTPS_KEY_PATH` - Path to a custom HTTPS certificate key when running `wrangler dev`, to be used with `WRANGLER_HTTPS_CERT_PATH`. -* `WRANGLER_HTTPS_CERT_PATH` +- `WRANGLER_HTTPS_CERT_PATH` - Path to a custom HTTPS certificate when running `wrangler dev`, to be used with `WRANGLER_HTTPS_KEY_PATH`. - `DOCKER_HOST` - Used for local development of [Containers](/containers/local-dev). Wrangler will attempt to automatically find the correct socket to use to communicate with your container engine. If that does not work (usually surfacing as an `internal error` when attempting to connect to your Container), you can try setting the socket path using this environment variable. -* `WRANGLER_R2_SQL_AUTH_TOKEN` +- `WRANGLER_R2_SQL_AUTH_TOKEN` - API token used for executing queries with [R2 SQL](/r2-sql). - `WRANGLER_OUTPUT_FILE_PATH` @@ -101,6 +101,11 @@ Wrangler supports the following environment variables: - `MINIFLARE_CACHE_DIR` - Custom directory for Miniflare's `cf.json` cache file, used during local development with `wrangler dev`. When set, this overrides the default cache location (`node_modules/.mf`). Useful for environments that do not use a traditional `node_modules` directory, such as Yarn PnP. +- `CLOUDFLARE_CF_FETCH_ENABLED` + - 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. + +- `CLOUDFLARE_CF_FETCH_PATH` + - 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. ### Example output file @@ -133,6 +138,7 @@ CLOUDFLARE_API_BASE_URL=https://api.cloudflare.com/client/v4 WRANGLER_LOG=debug WRANGLER_LOG_PATH=../Desktop/my-logs/my-log-file.log WRANGLER_R2_SQL_AUTH_TOKEN= +CLOUDFLARE_CF_FETCH_ENABLED=false ``` ## Deprecated global variables