wrangler 4.111.0 → 4.113.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config-schema.json +30 -23
- package/package.json +18 -17
- package/templates/middleware/middleware-miniflare3-json-error.ts +14 -4
- package/templates/startDevWorker/ProxyWorker.ts +1 -1
- package/wrangler-dist/cli.d.ts +84 -77
- package/wrangler-dist/cli.js +149696 -142275
- package/wrangler-dist/experimental-config.d.mts +138 -48
- package/wrangler-dist/experimental-config.d.mts.map +1 -1
- package/wrangler-dist/experimental-config.mjs +22 -4
- package/wrangler-dist/experimental-config.mjs.map +1 -1
- package/wrangler-dist/metafile-cjs.json +1 -1
- package/templates/remoteBindings/ProxyServerWorker.ts +0 -143
- package/templates/remoteBindings/wrangler.jsonc +0 -4
- package/wrangler-dist/ProxyServerWorker.js +0 -3314
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { newWorkersRpcResponse } from "capnweb";
|
|
2
|
-
import { EmailMessage } from "cloudflare:email";
|
|
3
|
-
|
|
4
|
-
interface Env extends Record<string, unknown> {}
|
|
5
|
-
|
|
6
|
-
class BindingNotFoundError extends Error {
|
|
7
|
-
constructor(name?: string) {
|
|
8
|
-
super(`Binding ${name ? `"${name}"` : ""} not found`);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* For most bindings, we expose them as
|
|
14
|
-
* - RPC stubs directly to capnweb, or
|
|
15
|
-
* - HTTP based fetchers
|
|
16
|
-
* However, there are some special cases:
|
|
17
|
-
* - SendEmail bindings need to take EmailMessage as their first parameter,
|
|
18
|
-
* which is not serialisable. As such, we reconstruct it before sending it
|
|
19
|
-
* on to the binding. See packages/miniflare/src/workers/email/email.worker.ts
|
|
20
|
-
* - Dispatch Namespace bindings have a synchronous .get() method. Since we
|
|
21
|
-
* can't emulate that over an async boundary, we mock it locally and _actually_
|
|
22
|
-
* perform the .get() remotely at the first appropriate async point. See
|
|
23
|
-
* packages/miniflare/src/workers/dispatch-namespace/dispatch-namespace.worker.ts
|
|
24
|
-
*
|
|
25
|
-
* getExposedJSRPCBinding() and getExposedFetcher() perform the logic for figuring out
|
|
26
|
-
* which binding is being accessed, dependending on the request. Note: Both have logic
|
|
27
|
-
* for dispatch namespaces, because dispatch namespaces can use both fetch or RPC depending
|
|
28
|
-
* on context.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
function getExposedJSRPCBinding(request: Request, env: Env) {
|
|
32
|
-
const url = new URL(request.url);
|
|
33
|
-
const bindingName = url.searchParams.get("MF-Binding");
|
|
34
|
-
if (!bindingName) {
|
|
35
|
-
throw new BindingNotFoundError();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const targetBinding = env[bindingName];
|
|
39
|
-
if (!targetBinding) {
|
|
40
|
-
throw new BindingNotFoundError(bindingName);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (targetBinding.constructor.name === "SendEmail") {
|
|
44
|
-
return {
|
|
45
|
-
async send(e: any) {
|
|
46
|
-
// Check if this is an EmailMessage (has EmailMessage::raw property) or MessageBuilder
|
|
47
|
-
if ("EmailMessage::raw" in e) {
|
|
48
|
-
// EmailMessage API - reconstruct the EmailMessage object
|
|
49
|
-
const message = new EmailMessage(
|
|
50
|
-
e.from,
|
|
51
|
-
e.to,
|
|
52
|
-
e["EmailMessage::raw"]
|
|
53
|
-
);
|
|
54
|
-
return (targetBinding as SendEmail).send(message);
|
|
55
|
-
} else {
|
|
56
|
-
// MessageBuilder API - pass through directly as a plain object
|
|
57
|
-
return (targetBinding as SendEmail).send(e);
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (url.searchParams.has("MF-Dispatch-Namespace-Options")) {
|
|
64
|
-
const { name, args, options } = JSON.parse(
|
|
65
|
-
url.searchParams.get("MF-Dispatch-Namespace-Options")!
|
|
66
|
-
);
|
|
67
|
-
return (targetBinding as DispatchNamespace).get(name, args, options);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return targetBinding;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function getExposedFetcher(request: Request, env: Env) {
|
|
74
|
-
const bindingName = request.headers.get("MF-Binding");
|
|
75
|
-
if (!bindingName) {
|
|
76
|
-
throw new BindingNotFoundError();
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const targetBinding = env[bindingName];
|
|
80
|
-
if (!targetBinding) {
|
|
81
|
-
throw new BindingNotFoundError(bindingName);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Special case the Dispatch Namespace binding because it has a top-level synchronous .get() call
|
|
85
|
-
const dispatchNamespaceOptions = request.headers.get(
|
|
86
|
-
"MF-Dispatch-Namespace-Options"
|
|
87
|
-
);
|
|
88
|
-
if (dispatchNamespaceOptions) {
|
|
89
|
-
const { name, args, options } = JSON.parse(dispatchNamespaceOptions);
|
|
90
|
-
return (targetBinding as DispatchNamespace).get(name, args, options);
|
|
91
|
-
}
|
|
92
|
-
return targetBinding as Fetcher;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* This Worker can proxy two types of remote binding:
|
|
97
|
-
* 1. "raw" bindings, where this Worker has been configured to pass through the raw
|
|
98
|
-
* fetch from a local workerd instance to the relevant binding
|
|
99
|
-
* 2. JSRPC bindings, where this Worker uses capnweb to proxy RPC
|
|
100
|
-
* communication in userland. This is always over a WebSocket connection
|
|
101
|
-
*/
|
|
102
|
-
function isJSRPCBinding(request: Request): boolean {
|
|
103
|
-
const url = new URL(request.url);
|
|
104
|
-
return request.headers.has("Upgrade") && url.searchParams.has("MF-Binding");
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export default {
|
|
108
|
-
async fetch(request, env) {
|
|
109
|
-
try {
|
|
110
|
-
if (isJSRPCBinding(request)) {
|
|
111
|
-
return await newWorkersRpcResponse(
|
|
112
|
-
request,
|
|
113
|
-
getExposedJSRPCBinding(request, env)
|
|
114
|
-
);
|
|
115
|
-
} else {
|
|
116
|
-
const fetcher = getExposedFetcher(request, env);
|
|
117
|
-
const originalHeaders = new Headers();
|
|
118
|
-
for (const [name, value] of request.headers) {
|
|
119
|
-
if (name.startsWith("mf-header-")) {
|
|
120
|
-
originalHeaders.set(name.slice("mf-header-".length), value);
|
|
121
|
-
} else if (name === "upgrade") {
|
|
122
|
-
// The `Upgrade` header needs to be special-cased to prevent:
|
|
123
|
-
// TypeError: Worker tried to return a WebSocket in a response to a request which did not contain the header "Upgrade: websocket"
|
|
124
|
-
originalHeaders.set(name, value);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return await fetcher.fetch(
|
|
129
|
-
request.headers.get("MF-URL") ?? "http://example.com",
|
|
130
|
-
new Request(request, {
|
|
131
|
-
redirect: "manual",
|
|
132
|
-
headers: originalHeaders,
|
|
133
|
-
})
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
} catch (e) {
|
|
137
|
-
if (e instanceof BindingNotFoundError) {
|
|
138
|
-
return new Response(e.message, { status: 400 });
|
|
139
|
-
}
|
|
140
|
-
return new Response((e as Error).message, { status: 500 });
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
} satisfies ExportedHandler<Env>;
|