From 6100add85a4ad606b4b6bbcb47a796d200919d42 Mon Sep 17 00:00:00 2001 From: emily-shen <69125074+emily-shen@users.noreply.github.com> Date: Wed, 9 Apr 2025 12:49:48 +0100 Subject: [PATCH 1/2] update email binding local --- src/content/partials/workers/bindings_per_env.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/content/partials/workers/bindings_per_env.mdx b/src/content/partials/workers/bindings_per_env.mdx index ab81c5de358c56..d5ef6c12a097a9 100644 --- a/src/content/partials/workers/bindings_per_env.mdx +++ b/src/content/partials/workers/bindings_per_env.mdx @@ -10,11 +10,11 @@ | --------------------------------------- | :---------------------: | :--------------------: | | **AI** | ✅[^1] | ✅ | | **Assets** | ✅ | ✅ | -| **Analytics Engine** | ✅[^4] | ✅ | +| **Analytics Engine** | ✅[^4] | ✅ | | **Browser Rendering** | ❌ | ✅ | | **D1** | ✅ | ✅ | | **Durable Objects** | ✅ | ✅ | -| **Email Bindings** | ❌ | ✅ | +| **Email Bindings** | ✅ | ✅ | | **Hyperdrive** | ✅[^2] | ✅ | | **Images** | ✅ | ✅ | | **KV** | ✅ | ✅ | From 7129d63198b498fce6b4314f0593aa525ec98503 Mon Sep 17 00:00:00 2001 From: emily-shen <69125074+emily-shen@users.noreply.github.com> Date: Wed, 9 Apr 2025 12:49:56 +0100 Subject: [PATCH 2/2] remove inaccessible page --- .../docs/workers/local-development.mdx | 160 ------------------ 1 file changed, 160 deletions(-) delete mode 100644 src/content/docs/workers/local-development.mdx diff --git a/src/content/docs/workers/local-development.mdx b/src/content/docs/workers/local-development.mdx deleted file mode 100644 index 8594168681dec9..00000000000000 --- a/src/content/docs/workers/local-development.mdx +++ /dev/null @@ -1,160 +0,0 @@ ---- -title: Local development -pcx_content_type: concept -sidebar: - order: 14 -head: [] -description: Develop your Workers locally via Wrangler. ---- - -import { Aside } from "~/components"; - -Cloudflare Workers and most connected resources can be fully developed and tested locally - providing confidence that the applications you build locally will work the same way in production. This allows you to be more efficient and effective by providing a faster feedback loop and removing the need to [test against remote resources](#develop-using-remote-resources-and-bindings). Local development runs against the same production runtime used by Cloudflare Workers, [workerd](https://github.com/cloudflare/workerd). - -In addition to testing Workers locally with [`wrangler dev`](/workers/wrangler/commands/#dev), the use of Miniflare allows you to test other Developer Platform products locally, such as [R2](/r2/), [KV](/kv/), [D1](/d1/), and [Durable Objects](/durable-objects/). - -## Start a local development server - -:::note - -This guide assumes you are using [Wrangler v3.0](https://blog.cloudflare.com/wrangler3/) or later. - -Users new to Wrangler CLI and Cloudflare Workers should visit the [Wrangler Install/Update guide](/workers/wrangler/install-and-update) to install `wrangler`. - -::: - -Wrangler provides a [`dev`](/workers/wrangler/commands/#dev) command that starts a local server for developing your Worker. Make sure you have `npm` installed and run the following in the folder containing your Worker application: - -```sh -npx wrangler dev -``` - -`wrangler dev` will run the Worker directly on your local machine. `wrangler dev` uses a combination of `workerd` and [Miniflare](https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare), a simulator that allows you to test your Worker against additional resources like KV, Durable Objects, WebSockets, and more. - -### Supported resource bindings in different environments - -| Product | Local Dev Supported | Remote Dev Supported | -| ----------------------------------- | ------------------- | -------------------- | -| AI | ✅[^1] | ✅ | -| Assets | ✅ | ✅ | -| Analytics Engine | ✅ | ✅ | -| Browser Rendering | ❌ | ✅ | -| D1 | ✅ | ✅ | -| Durable Objects | ✅ | ✅ [^2] | -| Email Bindings | ❌ | ✅ | -| Hyperdrive | ✅[^3] | ✅ | -| Images | ✅ | ✅ | -| KV | ✅ | ✅ | -| mTLS | ❌ | ✅ | -| Queues | ✅ | ❌ | -| R2 | ✅ | ✅ | -| Rate Limiting | ✅ | ✅ | -| Service Bindings (multiple workers) | ✅ | ✅ | -| Vectorize | ✅[^4] | ✅ | -| Workflows | ✅ | ❌ | - -With any bindings that are not supported locally, you will need to use the [`--remote` command](#develop-using-remote-resources-and-bindings) in wrangler, such as `wrangler dev --remote`. - -[^1]: Using Workers AI always accesses your Cloudflare account in order to run AI models and will incur usage charges even in local development. - -[^2]: For KV-backed Durable Objects only. SQLite-backed Durable Objects do not support remote development. - -[^3]: Using Hyperdrive with local development allows you to connect to a local database (running on `localhost`) but you cannot connect to a remote database. To connect to a remote database, use remote development. - -[^4]: Using Vectorize always accesses your Cloudflare account to run queries, and will incur usage charges even in local development. - -## Work with local data - -When running `wrangler dev`, resources such as KV, Durable Objects, D1, and R2 will be stored and persisted locally and not affect the production resources. - -### Use bindings in Wrangler configuration files - -[Wrangler](/workers/wrangler/) will automatically create local versions of bindings found in the [Wrangler configuration file](/workers/wrangler/configuration/). These local resources will not have data in them initially, so you will need to add data manually via Wrangler commands and the [`--local` flag](#use---local-flag). - -When you run `wrangler dev` Wrangler stores local resources in a `.wrangler/state` folder, which is automatically created. - -If you prefer to specify a directory, you can use the [`--persist-to`](/workers/wrangler/commands/#dev) flag with `wrangler dev` like this: - -```sh -npx wrangler dev --persist-to -``` - -Using this will write all local storage and cache to the specified directory instead of `.wrangler`. - -:::note - -This local persistence folder should be added to your `.gitignore` file. - -::: - -### Use `--local` flag - -The following [Wrangler commands](/workers/wrangler/commands/) have a `--local` flag which allows you to create, update, and delete local data during development: - -| Command | -| ---------------------------------------------------- | -| [`d1 execute`](/workers/wrangler/commands/#execute) | -| [`kv key`](/workers/wrangler/commands/#kv-key) | -| [`kv bulk`](/workers/wrangler/commands/#kv-bulk) | -| [`r2 object`](/workers/wrangler/commands/#r2-object) | - -If using `--persist-to` to specify a custom folder with `wrangler dev` you should also add `--persist-to` with the same directory name along with the `--local` flag when running the commands above. For example, to put a custom KV key into a local namespace via the CLI you would run: - -```sh -npx wrangler kv key put test 12345 --binding MY_KV_NAMESPACE --local --persist-to worker-local -``` - -Running `wrangler kv key put` will create a new key `test` with a value of `12345` on the local namespace specified via the binding `MY_KV_NAMESPACE` in the [Wrangler configuration file](/workers/wrangler/configuration/). This example command sets the local persistence directory to `worker-local` using `--persist-to`, to ensure that the data is created in the correct location. If `--persist-to` was not set, it would create the data in the `.wrangler` folder. - -### Clear Wrangler's local storage - -If you need to clear local storage entirely, delete the `.wrangler/state` folder. You can also be more fine-grained and delete specific resource folders within `.wrangler/state`. - -Any deleted folders will be created automatically the next time you run `wrangler dev`. - -## Local-only environment variables - -When running `wrangler dev`, variables in the [Wrangler configuration file](/workers/wrangler/configuration/) are automatically overridden by values defined in a `.dev.vars` file located in the root directory of your worker. This is useful for providing values you do not want to check in to source control. - -```shell -API_HOST = "localhost:4000" -API_ACCOUNT_ID = "local_example_user" -``` - -## Develop using remote resources and bindings - -There may be times you want to develop against remote resources and bindings. To run `wrangler dev` in remote mode, add the `--remote` flag, which will run both your code and resources remotely: - -```sh -npx wrangler dev --remote -``` - -For some products like KV and R2, remote resources used for `wrangler dev --remote` must be specified with preview ID/names in the [Wrangler configuration file](/workers/wrangler/configuration/) such as `preview_id` for KV or `preview_bucket name` for R2. Resources used for remote mode (preview) can be different from resources used for production to prevent changing production data during development. To use production data in `wrangler dev --remote`, set the preview ID/name of the resource to the ID/name of your production resource. - - - -## Customize `wrangler dev` - -You can customize how `wrangler dev` works to fit your needs. Refer to [the `wrangler dev` documentation](/workers/wrangler/commands/#dev) for available configuration options. - -:::caution - -There is a bug associated with how outgoing requests are handled when using `wrangler dev --remote`. For more information, read the [Known issues section](/workers/platform/known-issues/#wrangler-dev). - -::: - -## Related resources - -- [D1 local development](/d1/best-practices/local-development/) - The official D1 guide to local development and testing. -- [DevTools](/workers/observability/dev-tools) - Guides to using DevTools to debug your Worker locally.