-
Notifications
You must be signed in to change notification settings - Fork 770
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement support for service bindings
This adds experimental support for service bindings, aka worker-to-worker bindings. It's lets you "call" a worker from another worker, without incurring any network cost, and (ideally) with much less latency. To use it, define a `[services]` field in `wrangler.toml`, which is a map of bindings to worker names (and environment). Let's say you already have a worker named "my-worker" deployed. In another worker's configuration, you can create a service binding to it like so: ```toml [[services]] binding = "MYWORKER" service = "my-worker" environment = "production" # optional, defaults to the worker's `default_environment` for now ``` And in your worker, you can call it like so: ```js export default { fetch(req, env, ctx) { return env.MYWORKER.fetch(new Request("./some-path")); }, }; ``` Fixes #1026
- Loading branch information
1 parent
ffce3e3
commit 66f07c5
Showing
11 changed files
with
368 additions
and
49 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
feat: implement support for service bindings | ||
|
||
This adds experimental support for service bindings, aka worker-to-worker bindings. It's lets you "call" a worker from another worker, without incurring any network cost, and (ideally) with much less latency. To use it, define a `[services]` field in `wrangler.toml`, which is a map of bindings to worker names (and environment). Let's say you already have a worker named "my-worker" deployed. In another worker's configuration, you can create a service binding to it like so: | ||
|
||
```toml | ||
[[services]] | ||
binding = "MYWORKER" | ||
service = "my-worker" | ||
environment = "production" # optional, defaults to the worker's `default_environment` for now | ||
``` | ||
|
||
And in your worker, you can call it like so: | ||
|
||
```js | ||
export default { | ||
fetch(req, env, ctx) { | ||
return env.MYWORKER.fetch(new Request("./some-path")); | ||
}, | ||
}; | ||
``` | ||
|
||
Fixes https://github.com/cloudflare/wrangler2/issues/1026 |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.