Skip to content
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

Add support for named entrypoints #5215

Merged
merged 20 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
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 Mar 9, 2024
ad15f49
chore: exclude `miniflare` from monorepo's Prettier config
mrbbot Mar 20, 2024
1cb867b
fix: allow `script`s without `scriptPath`s to import built-ins
mrbbot Mar 20, 2024
b027cd4
feature: service binding named entrypoints for single-instance JSRPC
mrbbot Mar 20, 2024
22efef9
feature: direct socket named entrypoints for multi-instance JSRPC
mrbbot Mar 20, 2024
2ea552b
refactor: switch middleware to `external` services for dev registry
mrbbot Mar 21, 2024
da0b96e
feature: support binding to named entrypoints in `wrangler dev`
mrbbot Mar 22, 2024
a9fca83
feature: add middleware support to `WorkerEntrypoint`s
mrbbot Mar 23, 2024
cb89c7c
feature: add API for starting isolated dev registry
mrbbot Mar 25, 2024
9f652ca
fix: ensure `url` and `cf` blob preserved across service bindings
mrbbot Mar 25, 2024
756611e
test: add tests for named entrypoints and RPC
mrbbot Mar 25, 2024
3c4fd64
fixup! test: add tests for named entrypoints and RPC
mrbbot Mar 27, 2024
95494a1
fix: improve error message for cross-session Durable Object RPC
mrbbot Mar 27, 2024
8f62509
chore: move service binding assignment before Durable Objects
mrbbot Mar 27, 2024
c4afa70
fix: improve error message for RPC on not found service
mrbbot Mar 27, 2024
b839ef5
test: update deploy snapshot
mrbbot Apr 2, 2024
9abaa7b
Add test for binding to own named entrypoint
GregBrimble Apr 2, 2024
24aed14
fix: allow named entrypoints to current worker
mrbbot Apr 3, 2024
e469fb9
Simplify cross-Worker Durable Object RPC error message
GregBrimble Apr 3, 2024
d342bd6
Bump @cloudflare/workers-types@4.20240402.0
GregBrimble Apr 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/afraid-jeans-tap.md
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.
9 changes: 9 additions & 0 deletions .changeset/brown-cycles-live.md
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.
44 changes: 44 additions & 0 deletions .changeset/eight-seahorses-serve.md
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
```
GregBrimble marked this conversation as resolved.
Show resolved Hide resolved
7 changes: 7 additions & 0 deletions .changeset/lazy-papayas-knock.md
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`.
48 changes: 48 additions & 0 deletions .changeset/tidy-fans-speak.md
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.
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"); }
};
`,
},
],
});
```
2 changes: 1 addition & 1 deletion fixtures/additional-modules/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"devDependencies": {
"@cloudflare/workers-tsconfig": "workspace:*",
"@cloudflare/workers-types": "^4.20240320.1",
"@cloudflare/workers-types": "^4.20240402.0",
"undici": "^5.28.3",
"wrangler": "workspace:*"
}
Expand Down
15 changes: 15 additions & 0 deletions fixtures/entrypoints-rpc-tests/package.json
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"
}
}