-
Notifications
You must be signed in to change notification settings - Fork 774
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
feat: implement support for service bindings #906
Conversation
🦋 Changeset detectedLatest commit: afe7676 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/2337705327/npm-package-wrangler-906 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/906/npm-package-wrangler-906 Or you can use npx https://prerelease-registry.developers.workers.dev/runs/2337705327/npm-package-wrangler-906 dev path/to/script.js |
d6b0ee5
to
b90f512
Compare
b90f512
to
6ffc650
Compare
9ac761b
to
66f07c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bunch of NITs and suggestions. Nothing blocking landing this. Feel free to fix up and you see fit.
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("http://domain/some-path")); }, }; ``` Fixes #1026
66f07c5
to
afe7676
Compare
I can confirm the above syntax works however the one described in your documentation is not? I'm publishing my project using cloudflare/[email protected]. |
I noticed that in Workers docs and Miniflare there's inconsistency in how services are declared: - Workers expect `binding` key https://github.com/cloudflare/cloudflare-docs/blob/a65a35843ffb7b69caf2758cc5f2ad805251d166/content/workers/wrangler/configuration.md?plain=1#L212-L220 - Miniflare expects `name` I added 2 graceful and 2 error scenarios: - (graceful) accept `name` with warning if `binding` is missing - (graceful) accept `name` and `binding` both given and the same - (error) throw if both `binding` and `name` are given but they don't match - (error) throw if neither `binding` not `name` is given I decided to handle it with errors, not with mutually exclusive presence of either `name` or `binding` in interface `WranglerServiceConfig` because `name` should go away - it's just a behavior mismatch. Related: cloudflare#280 Syntax in wrangler2: cloudflare/workers-sdk#906
) * Allow helper `parsePluginWranglerConfig` to be given `Log` instances * Fix inconsistency: services have `binding` not `name` in `wrangler.toml` I noticed that in Workers docs and Miniflare there's inconsistency in how services are declared: - Workers expect `binding` key https://github.com/cloudflare/cloudflare-docs/blob/a65a35843ffb7b69caf2758cc5f2ad805251d166/content/workers/wrangler/configuration.md?plain=1#L212-L220 - Miniflare expects `name` I added 2 graceful and 2 error scenarios: - (graceful) accept `name` with warning if `binding` is missing - (graceful) accept `name` and `binding` both given and the same - (error) throw if both `binding` and `name` are given but they don't match - (error) throw if neither `binding` not `name` is given I decided to handle it with errors, not with mutually exclusive presence of either `name` or `binding` in interface `WranglerServiceConfig` because `name` should go away - it's just a behavior mismatch. Related: #280 Syntax in wrangler2: cloudflare/workers-sdk#906
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 inwrangler.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:And in your worker, you can call it like so:
Current critical drawbacks:
Fixes #1026