-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add support for named entrypoints #5215
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 all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
314a770
feature: support named entrypoints in `wrangler (pages) deploy`
GregBrimble ad15f49
chore: exclude `miniflare` from monorepo's Prettier config
mrbbot 1cb867b
fix: allow `script`s without `scriptPath`s to import built-ins
mrbbot b027cd4
feature: service binding named entrypoints for single-instance JSRPC
mrbbot 22efef9
feature: direct socket named entrypoints for multi-instance JSRPC
mrbbot 2ea552b
refactor: switch middleware to `external` services for dev registry
mrbbot da0b96e
feature: support binding to named entrypoints in `wrangler dev`
mrbbot a9fca83
feature: add middleware support to `WorkerEntrypoint`s
mrbbot cb89c7c
feature: add API for starting isolated dev registry
mrbbot 9f652ca
fix: ensure `url` and `cf` blob preserved across service bindings
mrbbot 756611e
test: add tests for named entrypoints and RPC
mrbbot 3c4fd64
fixup! test: add tests for named entrypoints and RPC
mrbbot 95494a1
fix: improve error message for cross-session Durable Object RPC
mrbbot 8f62509
chore: move service binding assignment before Durable Objects
mrbbot c4afa70
fix: improve error message for RPC on not found service
mrbbot b839ef5
test: update deploy snapshot
mrbbot 9abaa7b
Add test for binding to own named entrypoint
GregBrimble 24aed14
fix: allow named entrypoints to current worker
mrbbot e469fb9
Simplify cross-Worker Durable Object RPC error message
GregBrimble d342bd6
Bump @cloudflare/workers-types@4.20240402.0
GregBrimble 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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "wrangler": patch | ||
| --- | ||
|
|
||
| fix: ensure request `url` and `cf` properties preserved across service bindings | ||
|
|
||
| Previously, Wrangler could rewrite `url` and `cf` properties when sending requests via service bindings or Durable Object stubs. To match production behaviour, this change ensures these properties are preserved. |
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 |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| --- | ||
| "miniflare": minor | ||
| --- | ||
|
|
||
| feature: customisable unsafe direct sockets entrypoints | ||
|
|
||
| Previously, Miniflare provided experimental `unsafeDirectHost` and `unsafeDirectPort` options for starting an HTTP server that pointed directly to a specific Worker. This change replaces these options with a single `unsafeDirectSockets` option that accepts an array of socket objects of the form `{ host?: string, port?: number, entrypoint?: string, proxy?: boolean }`. `host` defaults to `127.0.0.1`, `port` defaults to `0`, `entrypoint` defaults to `default`, and `proxy` defaults to `false`. This allows you to start HTTP servers for specific entrypoints of specific Workers. `proxy` controls the [`Style`](https://github.com/cloudflare/workerd/blob/af35f1e7b0f166ec4ca93a8bf7daeacda029f11d/src/workerd/server/workerd.capnp#L780-L789) of the socket. | ||
|
|
||
| Note these sockets set the `capnpConnectHost` `workerd` option to `"miniflare-unsafe-internal-capnp-connect"`. `external` `serviceBindings` will set their `capnpConnectHost` option to the same value allowing RPC over multiple `Miniflare` instances. Refer to https://github.com/cloudflare/workerd/pull/1757 for more information. |
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 |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| --- | ||
| "wrangler": minor | ||
| --- | ||
|
|
||
| feature: support named entrypoints in service bindings | ||
|
|
||
| This change allows service bindings to bind to a named export of another Worker. As an example, consider the following Worker named `bound`: | ||
|
|
||
| ```ts | ||
| import { WorkerEntrypoint } from "cloudflare:workers"; | ||
|
|
||
| export class EntrypointA extends WorkerEntrypoint { | ||
| fetch(request) { | ||
| return new Response("Hello from entrypoint A!"); | ||
| } | ||
| } | ||
|
|
||
| export const entrypointB: ExportedHandler = { | ||
| fetch(request, env, ctx) { | ||
| return new Response("Hello from entrypoint B!"); | ||
| } | ||
| }; | ||
|
|
||
| export default <ExportedHandler>{ | ||
| fetch(request, env, ctx) { | ||
| return new Response("Hello from the default entrypoint!"); | ||
| } | ||
| }; | ||
| ``` | ||
|
|
||
| Up until now, you could only bind to the `default` entrypoint. With this change, you can bind to `EntrypointA` or `entrypointB` too using the new `entrypoint` option: | ||
|
|
||
| ```toml | ||
| [[services]] | ||
| binding = "SERVICE" | ||
| service = "bound" | ||
| entrypoint = "EntrypointA" | ||
| ``` | ||
|
|
||
| To bind to named entrypoints with `wrangler pages dev`, use the `#` character: | ||
|
|
||
| ```shell | ||
| $ wrangler pages dev --service=SERVICE=bound#EntrypointA | ||
| ``` | ||
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 |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "miniflare": patch | ||
| --- | ||
|
|
||
| fix: allow `script`s without `scriptPath`s to import built-in modules | ||
|
|
||
| Previously, if a string `script` option was specified with `modules: true` but without a corresponding `scriptPath`, all `import`s were forbidden. This change relaxes that restriction to allow imports of built-in `node:*`, `cloudflare:*` and `workerd:*` modules without a `scriptPath`. |
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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| --- | ||
| "miniflare": minor | ||
| --- | ||
|
|
||
| feature: support named entrypoints for `serviceBindings` | ||
|
|
||
| This change allows service bindings to bind to a named export of another Worker using designators of the form `{ name: string | typeof kCurrentWorker, entrypoint?: string }`. Previously, you could only bind to the `default` entrypoint. With this change, you can bind to any exported entrypoint. | ||
|
|
||
| ```ts | ||
| import { kCurrentWorker, Miniflare } from "miniflare"; | ||
|
|
||
| const mf = new Miniflare({ | ||
| workers: [ | ||
| { | ||
| name: "a", | ||
| serviceBindings: { | ||
| A_RPC_SERVICE: { name: kCurrentWorker, entrypoint: "RpcEntrypoint" }, | ||
| A_NAMED_SERVICE: { name: "a", entrypoint: "namedEntrypoint" }, | ||
RamIdeas marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| B_NAMED_SERVICE: { name: "b", entrypoint: "anotherNamedEntrypoint" }, | ||
| }, | ||
| compatibilityFlags: ["rpc"], | ||
| modules: true, | ||
| script: ` | ||
| import { WorkerEntrypoint } from "cloudflare:workers"; | ||
|
|
||
| export class RpcEntrypoint extends WorkerEntrypoint { | ||
| ping() { return "a:rpc:pong"; } | ||
| } | ||
|
|
||
| export const namedEntrypoint = { | ||
| fetch(request, env, ctx) { return new Response("a:named:pong"); } | ||
| }; | ||
|
|
||
| ... | ||
| `, | ||
| }, | ||
| { | ||
| name: "b", | ||
| modules: true, | ||
| script: ` | ||
| export const anotherNamedEntrypoint = { | ||
| fetch(request, env, ctx) { return new Response("b:named:pong"); } | ||
| }; | ||
| `, | ||
| }, | ||
| ], | ||
| }); | ||
| ``` | ||
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
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 |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| { | ||
| "name": "entrypoints-rpc-tests", | ||
| "private": true, | ||
| "scripts": { | ||
| "test": "vitest run", | ||
| "test:ci": "vitest run", | ||
| "test:watch": "vitest" | ||
| }, | ||
| "devDependencies": { | ||
| "@cloudflare/workers-tsconfig": "workspace:*", | ||
| "wrangler": "workspace:*", | ||
| "ts-dedent": "^2.2.0", | ||
| "undici": "^5.28.3" | ||
| } | ||
| } |
Oops, something went wrong.
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.