-
Notifications
You must be signed in to change notification settings - Fork 16k
pages: add sections about local support for bindings in wrangler.toml #12731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -55,6 +55,14 @@ export const onRequest: PagesFunction<Env> = async (context) => { | |
|
|
||
| While developing locally, interact with your KV namespace by adding `-k <BINDING_NAME>` or `--kv=<BINDING_NAME>` to your run command. For example, if your namespace is bound to `TODO_LIST`, access the KV namespace in your local dev by running `npx wrangler pages dev <OUTPUT_DIR> --kv=TODO_LIST`. The data from this namespace can be accessed using `context.env.TODO_LIST`. | ||
|
|
||
| Alternatively, you can interact with a KV namespace locally via a `wrangler.toml` file. See [Wrangler configuration](/workers/wrangler/configuration/#kv-namespaces) for more information. | ||
|
|
||
| {{<Aside type="note">}} | ||
|
|
||
| `wrangler.toml` is currently **only** used for local development. Bindings specified in it are not available remotely. | ||
|
|
||
| {{</Aside>}} | ||
|
|
||
| ## Durable Object namespaces | ||
|
|
||
| [Durable Objects](/durable-objects/) (DO) are Cloudflare's strongly consistent data store that power capabilities such as connecting WebSockets and handling state. To bind your DO namespace to your Pages Function: | ||
|
|
@@ -147,7 +155,21 @@ export const onRequest: PagesFunction<Env> = async (context) => { | |
|
|
||
| ### Interact with your R2 buckets locally | ||
|
|
||
| While developing locally, interact with an R2 bucket by adding `--r2=<BINDING_NAME>` to your run command. For example, if your bucket is bound to `BUCKET`, access this bucket in local dev by running `npx wrangler pages dev <OUTPUT_DIR> --r2=BUCKET`. Interact with this binding by using `context.env` (for example, `context.env.BUCKET`). | ||
| While developing locally, interact with an R2 bucket by adding `--r2=<BINDING_NAME>` to your run command. | ||
|
|
||
| {{<Aside type="note">}} | ||
| By default, `wrangler dev` automatically persists data. | ||
| {{</Aside>}} | ||
|
|
||
| If your bucket is bound to `BUCKET`, access this bucket in local dev by running `npx wrangler pages dev <OUTPUT_DIR> --r2=BUCKET`. Interact with this binding by using `context.env` (for example, `context.env.BUCKET`). | ||
|
|
||
| Alternatively, you can interact with an R2 bucket locally via a `wrangler.toml` file. See [Wrangler configuration](/workers/wrangler/configuration/#r2-buckets) for more information. | ||
|
deadlypants1973 marked this conversation as resolved.
Outdated
|
||
|
|
||
| {{<Aside type="note">}} | ||
|
|
||
| `wrangler.toml` is currently **only** used for local development. Bindings specified in it are not available remotely. | ||
|
|
||
| {{</Aside>}} | ||
|
|
||
| ## D1 databases | ||
|
|
||
|
|
@@ -207,6 +229,14 @@ Specifically: | |
|
|
||
| Refer to the [D1 client API documentation](/d1/how-to/query-databases/) for the API methods available on your D1 binding. | ||
|
|
||
| Alternatively, you can interact with a D1 database locally via a `wrangler.toml` file. See [Wrangler configuration](/workers/wrangler/configuration/#d1-databases) for more information. | ||
|
deadlypants1973 marked this conversation as resolved.
Outdated
|
||
|
|
||
| {{<Aside type="note">}} | ||
|
|
||
| `wrangler.toml` is currently **only** used for local development. Bindings specified in it are not available remotely. | ||
|
|
||
| {{</Aside>}} | ||
|
|
||
| ## Workers AI | ||
| [Workers AI](/workers-ai/) allows you to run powerful AI models. To bind Workers AI to your Pages Function: | ||
|
|
||
|
|
@@ -306,6 +336,14 @@ export const onRequest: PagesFunction<Env> = async (context) => { | |
|
|
||
| To interact with a [service binding](/workers/configuration/bindings/about-service-bindings/) while developing locally, run the Worker you want to bind to via `wrangler dev` and in parallel, run `wrangler pages dev` with `--service <BINDING_NAME>=<SCRIPT_NAME>` where `SCRIPT_NAME` indicates the name of the Worker. For example, if your Worker is called `my-worker`, connect with this Worker by running it via `npx wrangler dev` (in the Worker's directory) alongside `npx wrangler pages dev <OUTPUT_DIR> --service MY_SERVICE=my-worker` (in the Pages' directory). Interact with this binding by using `context.env` (for example, `context.env.MY_SERVICE`). | ||
|
|
||
| Alternatively, you can interact with a service binding locally via a `wrangler.toml` file. See [Wrangler configuration](/workers/wrangler/configuration/#service-bindings) for more information. | ||
|
deadlypants1973 marked this conversation as resolved.
Outdated
|
||
|
|
||
| {{<Aside type="note">}} | ||
|
|
||
| `wrangler.toml` is currently **only** used for local development. Bindings specified in it are not available remotely. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These callouts are very helpful |
||
|
|
||
| {{</Aside>}} | ||
|
|
||
| ## Queue Producers | ||
|
|
||
| [Queue Producers](/queues/reference/javascript-apis/#producer) enable you to send messages into a Queue within your Pages Function. To add a Queue producer binding to your Pages Function: | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.