wrangler 0.0.0-e9c2b04a → 0.0.0-e9f8a2fa
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/README.md +1 -1
- package/config-schema.json +2939 -0
- package/package.json +38 -29
- package/templates/checked-fetch.js +1 -1
- package/templates/facade.d.ts +7 -5
- package/templates/gitignore +0 -5
- package/templates/init-tests/test-vitest-new-worker.js +1 -1
- package/templates/init-tests/test-vitest-new-worker.ts +1 -1
- package/templates/middleware/loader-modules.ts +93 -97
- package/templates/middleware/loader-sw.ts +4 -3
- package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +0 -1
- package/templates/middleware/middleware-serve-static-assets.ts +5 -5
- package/templates/pages-dev-pipeline.ts +2 -1
- package/templates/pages-template-plugin.ts +2 -2
- package/templates/pages-template-worker.ts +1 -1
- package/templates/startDevWorker/InspectorProxyWorker.ts +17 -5
- package/templates/startDevWorker/ProxyWorker.ts +122 -40
- package/wrangler-dist/InspectorProxyWorker.js +4 -0
- package/wrangler-dist/InspectorProxyWorker.js.map +1 -1
- package/wrangler-dist/ProxyWorker.js +78 -24
- package/wrangler-dist/ProxyWorker.js.map +1 -1
- package/wrangler-dist/cli.d.ts +772 -248
- package/wrangler-dist/cli.js +79134 -32915
- package/templates/middleware/middleware-d1-beta.d.ts +0 -3
- package/templates/middleware/middleware-multiworker-dev.d.ts +0 -4
- package/templates/middleware/middleware-multiworker-dev.ts +0 -68
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-e9f8a2fa",
|
|
4
4
|
"description": "Command-line interface for all things Cloudflare Workers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wrangler",
|
|
@@ -47,15 +47,10 @@
|
|
|
47
47
|
"wrangler-dist",
|
|
48
48
|
"templates",
|
|
49
49
|
"kv-asset-handler.js",
|
|
50
|
-
"Cloudflare_CA.pem"
|
|
50
|
+
"Cloudflare_CA.pem",
|
|
51
|
+
"config-schema.json"
|
|
51
52
|
],
|
|
52
53
|
"jest": {
|
|
53
|
-
"coverageReporters": [
|
|
54
|
-
"json",
|
|
55
|
-
"html",
|
|
56
|
-
"text",
|
|
57
|
-
"cobertura"
|
|
58
|
-
],
|
|
59
54
|
"moduleNameMapper": {
|
|
60
55
|
"clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",
|
|
61
56
|
"miniflare/cli": "<rootDir>/../../node_modules/miniflare/dist/src/cli.js"
|
|
@@ -75,16 +70,15 @@
|
|
|
75
70
|
]
|
|
76
71
|
},
|
|
77
72
|
"transformIgnorePatterns": [
|
|
78
|
-
"node_modules/.pnpm/(?!find-up|locate-path|p-locate|p-limit|p-timeout|p-queue|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream|get-port|supports-color|pretty-bytes)"
|
|
73
|
+
"node_modules/.pnpm/(?!find-up|locate-path|p-locate|p-limit|p-timeout|p-queue|yocto-queue|path-exists|execa|strip-final-newline|npm-run-path|path-key|onetime|mimic-fn|human-signals|is-stream|get-port|supports-color|pretty-bytes|strip-ansi|ansi-regex)"
|
|
79
74
|
],
|
|
80
75
|
"snapshotFormat": {
|
|
81
76
|
"escapeString": true,
|
|
82
77
|
"printBasicPrototype": true
|
|
83
|
-
}
|
|
78
|
+
},
|
|
79
|
+
"prettierPath": null
|
|
84
80
|
},
|
|
85
81
|
"dependencies": {
|
|
86
|
-
"@cloudflare/kv-asset-handler": "^0.2.0",
|
|
87
|
-
"@cspotcode/source-map-support": "0.8.1",
|
|
88
82
|
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
|
89
83
|
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
|
90
84
|
"blake3-wasm": "^2.1.5",
|
|
@@ -92,24 +86,24 @@
|
|
|
92
86
|
"esbuild": "0.17.19",
|
|
93
87
|
"nanoid": "^3.3.3",
|
|
94
88
|
"path-to-regexp": "^6.2.0",
|
|
89
|
+
"resolve": "^1.22.8",
|
|
95
90
|
"resolve.exports": "^2.0.2",
|
|
96
91
|
"selfsigned": "^2.0.1",
|
|
97
92
|
"source-map": "0.6.1",
|
|
98
93
|
"xxhash-wasm": "^1.0.1",
|
|
99
|
-
"
|
|
94
|
+
"@cloudflare/kv-asset-handler": "0.3.2",
|
|
95
|
+
"miniflare": "3.20240512.0"
|
|
100
96
|
},
|
|
101
97
|
"devDependencies": {
|
|
102
|
-
"@cloudflare/ai": "^1.0.35",
|
|
103
|
-
"@cloudflare/eslint-config-worker": "*",
|
|
104
98
|
"@cloudflare/types": "^6.18.4",
|
|
105
|
-
"@cloudflare/workers-types": "^4.
|
|
99
|
+
"@cloudflare/workers-types": "^4.20240512.0",
|
|
100
|
+
"@cspotcode/source-map-support": "0.8.1",
|
|
106
101
|
"@iarna/toml": "^3.0.0",
|
|
107
102
|
"@microsoft/api-extractor": "^7.28.3",
|
|
108
103
|
"@sentry/node": "^7.86.0",
|
|
109
104
|
"@sentry/types": "^7.86.0",
|
|
110
105
|
"@sentry/utils": "^7.86.0",
|
|
111
106
|
"@types/body-parser": "^1.19.2",
|
|
112
|
-
"@types/busboy": "^1.5.0",
|
|
113
107
|
"@types/command-exists": "^1.2.0",
|
|
114
108
|
"@types/express": "^4.17.13",
|
|
115
109
|
"@types/glob-to-regexp": "0.4.1",
|
|
@@ -120,13 +114,14 @@
|
|
|
120
114
|
"@types/minimatch": "^5.1.2",
|
|
121
115
|
"@types/prompts": "^2.0.14",
|
|
122
116
|
"@types/react": "^17.0.37",
|
|
117
|
+
"@types/resolve": "^1.20.6",
|
|
123
118
|
"@types/serve-static": "^1.13.10",
|
|
124
119
|
"@types/shell-quote": "^1.7.2",
|
|
125
120
|
"@types/signal-exit": "^3.0.1",
|
|
126
|
-
"@types/source-map-support": "^0.5.7",
|
|
127
121
|
"@types/supports-color": "^8.1.1",
|
|
128
122
|
"@types/ws": "^8.5.3",
|
|
129
123
|
"@types/yargs": "^17.0.10",
|
|
124
|
+
"@vitest/ui": "^1.6.0",
|
|
130
125
|
"@webcontainer/env": "^1.1.0",
|
|
131
126
|
"body-parser": "^1.20.0",
|
|
132
127
|
"chalk": "^2.4.2",
|
|
@@ -137,10 +132,10 @@
|
|
|
137
132
|
"concurrently": "^7.2.2",
|
|
138
133
|
"devtools-protocol": "^0.0.955664",
|
|
139
134
|
"dotenv": "^16.0.0",
|
|
135
|
+
"es-module-lexer": "^1.3.0",
|
|
140
136
|
"esbuild-jest": "0.5.0",
|
|
141
137
|
"execa": "^6.1.0",
|
|
142
138
|
"express": "^4.18.1",
|
|
143
|
-
"finalhandler": "^1.2.0",
|
|
144
139
|
"find-up": "^6.3.0",
|
|
145
140
|
"get-port": "^6.1.2",
|
|
146
141
|
"glob-to-regexp": "0.4.1",
|
|
@@ -151,13 +146,12 @@
|
|
|
151
146
|
"ink-select-input": "^4.2.1",
|
|
152
147
|
"ink-spinner": "^4.0.3",
|
|
153
148
|
"ink-table": "^3.0.0",
|
|
154
|
-
"ink-testing-library": "^2.1.0",
|
|
155
|
-
"ink-text-input": "^4.0.3",
|
|
156
149
|
"is-ci": "^3.0.1",
|
|
157
150
|
"javascript-time-ago": "^2.5.4",
|
|
158
151
|
"jest": "^29.7.0",
|
|
159
152
|
"jest-fetch-mock": "^3.0.3",
|
|
160
153
|
"jest-websocket-mock": "^2.5.0",
|
|
154
|
+
"md5-file": "5.0.0",
|
|
161
155
|
"mime": "^3.0.0",
|
|
162
156
|
"minimatch": "^5.1.0",
|
|
163
157
|
"msw": "^0.49.1",
|
|
@@ -166,9 +160,9 @@
|
|
|
166
160
|
"patch-console": "^1.0.0",
|
|
167
161
|
"pretty-bytes": "^6.0.0",
|
|
168
162
|
"prompts": "^2.4.2",
|
|
163
|
+
"ps-list": "^8.1.1",
|
|
169
164
|
"react": "^17.0.2",
|
|
170
165
|
"react-error-boundary": "^3.1.4",
|
|
171
|
-
"remove-accents-esm": "^0.0.1",
|
|
172
166
|
"semiver": "^1.1.0",
|
|
173
167
|
"serve-static": "^1.15.0",
|
|
174
168
|
"shell-quote": "^1.8.1",
|
|
@@ -178,36 +172,51 @@
|
|
|
178
172
|
"supports-color": "^9.2.2",
|
|
179
173
|
"timeago.js": "^4.0.2",
|
|
180
174
|
"ts-dedent": "^2.2.0",
|
|
181
|
-
"
|
|
175
|
+
"ts-json-schema-generator": "^1.5.0",
|
|
176
|
+
"undici": "5.28.4",
|
|
182
177
|
"update-check": "^1.5.4",
|
|
178
|
+
"vitest": "^1.6.0",
|
|
183
179
|
"ws": "^8.5.0",
|
|
184
180
|
"xdg-app-paths": "^8.3.0",
|
|
185
181
|
"yargs": "^17.7.2",
|
|
186
182
|
"yoga-layout": "file:../../vendor/yoga-layout-2.0.0-beta.1.tgz",
|
|
187
|
-
"@cloudflare/cli": "1.
|
|
188
|
-
"@cloudflare/
|
|
189
|
-
"@cloudflare/workers-tsconfig": "0.0.0"
|
|
183
|
+
"@cloudflare/cli": "1.1.1",
|
|
184
|
+
"@cloudflare/eslint-config-worker": "1.1.0",
|
|
185
|
+
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
186
|
+
"@cloudflare/pages-shared": "^0.11.36"
|
|
190
187
|
},
|
|
191
188
|
"optionalDependencies": {
|
|
192
189
|
"fsevents": "~2.3.2"
|
|
193
190
|
},
|
|
191
|
+
"peerDependencies": {
|
|
192
|
+
"@cloudflare/workers-types": "^4.20240512.0"
|
|
193
|
+
},
|
|
194
|
+
"peerDependenciesMeta": {
|
|
195
|
+
"@cloudflare/workers-types": {
|
|
196
|
+
"optional": true
|
|
197
|
+
}
|
|
198
|
+
},
|
|
194
199
|
"engines": {
|
|
195
200
|
"node": ">=16.17.0"
|
|
196
201
|
},
|
|
202
|
+
"workers-sdk": {
|
|
203
|
+
"prerelease": true
|
|
204
|
+
},
|
|
197
205
|
"scripts": {
|
|
198
206
|
"assert-git-version": "node -r esbuild-register scripts/assert-git-version.ts",
|
|
199
|
-
"build": "pnpm run clean && pnpm run bundle && pnpm run emit-types",
|
|
207
|
+
"build": "pnpm run clean && pnpm run bundle && pnpm run emit-types && pnpm run generate-json-schema",
|
|
200
208
|
"bundle": "node -r esbuild-register scripts/bundle.ts",
|
|
201
209
|
"check:lint": "eslint .",
|
|
202
210
|
"check:type": "tsc",
|
|
203
211
|
"clean": "rimraf wrangler-dist miniflare-dist emitted-types",
|
|
204
212
|
"dev": "pnpm run clean && concurrently -c black,blue --kill-others-on-fail false \"pnpm run bundle --watch\" \"pnpm run check:type --watch --preserveWatchOutput\"",
|
|
205
213
|
"emit-types": "tsc -p tsconfig.emit.json && node -r esbuild-register scripts/emit-types.ts",
|
|
214
|
+
"generate-json-schema": "pnpm exec ts-json-schema-generator --no-type-check --path src/config/config.ts --type RawConfig --out config-schema.json",
|
|
206
215
|
"start": "pnpm run bundle && cross-env NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
|
|
207
216
|
"test": "pnpm run assert-git-version && jest",
|
|
208
|
-
"test:ci": "pnpm run test
|
|
217
|
+
"test:ci": "pnpm run test",
|
|
209
218
|
"test:debug": "pnpm run test --silent=false --verbose=true",
|
|
210
|
-
"test:e2e": "vitest
|
|
219
|
+
"test:e2e": "vitest -c ./e2e/vitest.config.ts",
|
|
211
220
|
"test:watch": "pnpm run test --testTimeout=50000 --watch",
|
|
212
221
|
"type:tests": "tsc -p ./src/__tests__/tsconfig.json && tsc -p ./e2e/tsconfig.json"
|
|
213
222
|
}
|
package/templates/facade.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
declare module "__ENTRY_POINT__" {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
2
|
+
import { Middleware } from "./middleware/common";
|
|
3
|
+
import { WorkerEntrypoint } from "cloudflare:workers";
|
|
4
|
+
|
|
5
|
+
export type WorkerEntrypointConstructor = typeof WorkerEntrypoint;
|
|
6
|
+
export type WithMiddleware<T> = T & { middleware?: Middleware[] };
|
|
7
|
+
|
|
8
|
+
const worker: WithMiddleware<ExportedHandler | WorkerEntrypointConstructor>;
|
|
7
9
|
export default worker;
|
|
8
10
|
}
|
|
9
11
|
|
package/templates/gitignore
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { afterAll, beforeAll, describe, expect, it } from "vitest";
|
|
1
2
|
import { unstable_dev } from "wrangler";
|
|
2
3
|
import type { UnstableDevWorker } from "wrangler";
|
|
3
|
-
import { describe, expect, it, beforeAll, afterAll } from "vitest";
|
|
4
4
|
|
|
5
5
|
describe("Worker", () => {
|
|
6
6
|
let worker: UnstableDevWorker;
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import worker from "__ENTRY_POINT__";
|
|
15
|
-
|
|
16
|
-
// We need to preserve all of the exports from the worker
|
|
1
|
+
// This loads all middlewares exposed on the middleware object and then starts
|
|
2
|
+
// the invocation chain. The big idea is that we can add these to the middleware
|
|
3
|
+
// export dynamically through wrangler, or we can potentially let users directly
|
|
4
|
+
// add them as a sort of "plugin" system.
|
|
5
|
+
|
|
6
|
+
import ENTRY from "__ENTRY_POINT__";
|
|
7
|
+
import { __facade_invoke__, __facade_register__, Dispatcher } from "./common";
|
|
8
|
+
import type {
|
|
9
|
+
WithMiddleware,
|
|
10
|
+
WorkerEntrypointConstructor,
|
|
11
|
+
} from "__ENTRY_POINT__";
|
|
12
|
+
|
|
13
|
+
// Preserve all the exports from the worker
|
|
17
14
|
export * from "__ENTRY_POINT__";
|
|
18
15
|
|
|
19
16
|
class __Facade_ScheduledController__ implements ScheduledController {
|
|
20
|
-
#noRetry: ScheduledController["noRetry"];
|
|
17
|
+
readonly #noRetry: ScheduledController["noRetry"];
|
|
21
18
|
|
|
22
19
|
constructor(
|
|
23
20
|
readonly scheduledTime: number,
|
|
@@ -36,71 +33,33 @@ class __Facade_ScheduledController__ implements ScheduledController {
|
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
35
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
function getMaskedEnv(rawEnv: unknown) {
|
|
50
|
-
let env = rawEnv as Record<string, unknown>;
|
|
51
|
-
if (worker.envWrappers && worker.envWrappers.length > 0) {
|
|
52
|
-
for (const wrapFn of worker.envWrappers) {
|
|
53
|
-
env = wrapFn(env);
|
|
54
|
-
}
|
|
36
|
+
function wrapExportedHandler(
|
|
37
|
+
worker: WithMiddleware<ExportedHandler>
|
|
38
|
+
): ExportedHandler {
|
|
39
|
+
// If we don't have any middleware defined, just return the handler as is
|
|
40
|
+
if (worker.middleware === undefined || worker.middleware.length === 0) {
|
|
41
|
+
return worker;
|
|
42
|
+
}
|
|
43
|
+
// Otherwise, register all middleware once
|
|
44
|
+
for (const middleware of worker.middleware) {
|
|
45
|
+
__facade_register__(middleware);
|
|
55
46
|
}
|
|
56
|
-
return env;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* This type is here to cause a type error if a new export handler is added to
|
|
61
|
-
* `ExportHandler` without it being included in the `facade` below.
|
|
62
|
-
*/
|
|
63
|
-
type MissingExportHandlers = Omit<
|
|
64
|
-
Required<ExportedHandler>,
|
|
65
|
-
"tail" | "trace" | "scheduled" | "queue" | "test" | "email" | "fetch"
|
|
66
|
-
>;
|
|
67
|
-
|
|
68
|
-
let registeredMiddleware = false;
|
|
69
|
-
|
|
70
|
-
const facade: ExportedHandler<unknown> & MissingExportHandlers = {
|
|
71
|
-
...(worker.tail && {
|
|
72
|
-
tail: maskHandlerEnv(worker.tail),
|
|
73
|
-
}),
|
|
74
|
-
...(worker.trace && {
|
|
75
|
-
trace: maskHandlerEnv(worker.trace),
|
|
76
|
-
}),
|
|
77
|
-
...(worker.scheduled && {
|
|
78
|
-
scheduled: maskHandlerEnv(worker.scheduled),
|
|
79
|
-
}),
|
|
80
|
-
...(worker.queue && {
|
|
81
|
-
queue: maskHandlerEnv(worker.queue),
|
|
82
|
-
}),
|
|
83
|
-
...(worker.test && {
|
|
84
|
-
test: maskHandlerEnv(worker.test),
|
|
85
|
-
}),
|
|
86
|
-
...(worker.email && {
|
|
87
|
-
email: maskHandlerEnv(worker.email),
|
|
88
|
-
}),
|
|
89
47
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
}
|
|
48
|
+
const fetchDispatcher: ExportedHandlerFetchHandler = function (
|
|
49
|
+
request,
|
|
50
|
+
env,
|
|
51
|
+
ctx
|
|
52
|
+
) {
|
|
53
|
+
if (worker.fetch === undefined) {
|
|
54
|
+
throw new Error("Handler does not export a fetch() function.");
|
|
55
|
+
}
|
|
56
|
+
return worker.fetch(request, env, ctx);
|
|
57
|
+
};
|
|
102
58
|
|
|
103
|
-
|
|
59
|
+
return {
|
|
60
|
+
...worker,
|
|
61
|
+
fetch(request, env, ctx) {
|
|
62
|
+
const dispatcher: Dispatcher = function (type, init) {
|
|
104
63
|
if (type === "scheduled" && worker.scheduled !== undefined) {
|
|
105
64
|
const controller = new __Facade_ScheduledController__(
|
|
106
65
|
Date.now(),
|
|
@@ -110,28 +69,65 @@ const facade: ExportedHandler<unknown> & MissingExportHandlers = {
|
|
|
110
69
|
return worker.scheduled(controller, env, ctx);
|
|
111
70
|
}
|
|
112
71
|
};
|
|
72
|
+
return __facade_invoke__(request, env, ctx, dispatcher, fetchDispatcher);
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function wrapWorkerEntrypoint(
|
|
78
|
+
klass: WithMiddleware<WorkerEntrypointConstructor>
|
|
79
|
+
): WorkerEntrypointConstructor {
|
|
80
|
+
// If we don't have any middleware defined, just return the handler as is
|
|
81
|
+
if (klass.middleware === undefined || klass.middleware.length === 0) {
|
|
82
|
+
return klass;
|
|
83
|
+
}
|
|
84
|
+
// Otherwise, register all middleware once
|
|
85
|
+
for (const middleware of klass.middleware) {
|
|
86
|
+
__facade_register__(middleware);
|
|
87
|
+
}
|
|
113
88
|
|
|
89
|
+
// `extend`ing `klass` here so other RPC methods remain callable
|
|
90
|
+
return class extends klass {
|
|
91
|
+
#fetchDispatcher: ExportedHandlerFetchHandler<Record<string, unknown>> = (
|
|
92
|
+
request,
|
|
93
|
+
env,
|
|
94
|
+
ctx
|
|
95
|
+
) => {
|
|
96
|
+
this.env = env;
|
|
97
|
+
this.ctx = ctx;
|
|
98
|
+
if (super.fetch === undefined) {
|
|
99
|
+
throw new Error("Entrypoint class does not define a fetch() function.");
|
|
100
|
+
}
|
|
101
|
+
return super.fetch(request);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
#dispatcher: Dispatcher = (type, init) => {
|
|
105
|
+
if (type === "scheduled" && super.scheduled !== undefined) {
|
|
106
|
+
const controller = new __Facade_ScheduledController__(
|
|
107
|
+
Date.now(),
|
|
108
|
+
init.cron ?? "",
|
|
109
|
+
() => {}
|
|
110
|
+
);
|
|
111
|
+
return super.scheduled(controller);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
fetch(request: Request<unknown, IncomingRequestCfProperties>) {
|
|
114
116
|
return __facade_invoke__(
|
|
115
117
|
request,
|
|
116
|
-
env,
|
|
117
|
-
ctx,
|
|
118
|
-
|
|
119
|
-
|
|
118
|
+
this.env,
|
|
119
|
+
this.ctx,
|
|
120
|
+
this.#dispatcher,
|
|
121
|
+
this.#fetchDispatcher
|
|
120
122
|
);
|
|
121
|
-
} else {
|
|
122
|
-
// We didn't have any middleware so we can skip the invocation chain,
|
|
123
|
-
// and just call the fetch handler directly
|
|
124
|
-
|
|
125
|
-
// We "don't care" if this is undefined as we want to have the same behavior
|
|
126
|
-
// as if the worker completely bypassed middleware.
|
|
127
|
-
return __facade_modules_fetch__(request, env, ctx);
|
|
128
123
|
}
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
type HandlerFn<D, R> = (data: D, env: unknown, ctx: ExecutionContext) => R;
|
|
133
|
-
function maskHandlerEnv<D, R>(handler: HandlerFn<D, R>): HandlerFn<D, R> {
|
|
134
|
-
return (data, env, ctx) => handler(data, getMaskedEnv(env), ctx);
|
|
124
|
+
};
|
|
135
125
|
}
|
|
136
126
|
|
|
137
|
-
|
|
127
|
+
let WRAPPED_ENTRY: ExportedHandler | WorkerEntrypointConstructor | undefined;
|
|
128
|
+
if (typeof ENTRY === "object") {
|
|
129
|
+
WRAPPED_ENTRY = wrapExportedHandler(ENTRY);
|
|
130
|
+
} else if (typeof ENTRY === "function") {
|
|
131
|
+
WRAPPED_ENTRY = wrapWorkerEntrypoint(ENTRY);
|
|
132
|
+
}
|
|
133
|
+
export default WRAPPED_ENTRY;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
+
__facade_invoke__,
|
|
3
|
+
__facade_register__,
|
|
4
|
+
__facade_registerInternal__,
|
|
2
5
|
Awaitable,
|
|
3
6
|
Dispatcher,
|
|
4
7
|
IncomingRequest,
|
|
5
8
|
Middleware,
|
|
6
|
-
__facade_invoke__,
|
|
7
|
-
__facade_register__,
|
|
8
|
-
__facade_registerInternal__,
|
|
9
9
|
} from "./common";
|
|
10
|
+
|
|
10
11
|
export { __facade_register__, __facade_registerInternal__ };
|
|
11
12
|
|
|
12
13
|
// Miniflare 2's `EventTarget` follows the spec and doesn't allow exceptions to
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Middleware } from "./common";
|
|
2
|
+
|
|
3
|
+
const drainBody: Middleware = async (request, env, _ctx, middlewareCtx) => {
|
|
4
|
+
try {
|
|
5
|
+
return await middlewareCtx.next(request, env);
|
|
6
|
+
} finally {
|
|
7
|
+
try {
|
|
8
|
+
if (request.body !== null && !request.bodyUsed) {
|
|
9
|
+
const reader = request.body.getReader();
|
|
10
|
+
while (!(await reader.read()).done) {}
|
|
11
|
+
}
|
|
12
|
+
} catch (e) {
|
|
13
|
+
console.error("Failed to drain the unused request body.", e);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default drainBody;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
/// <reference path="middleware-serve-static-assets.d.ts"/>
|
|
2
2
|
|
|
3
|
+
import manifest from "__STATIC_CONTENT_MANIFEST";
|
|
3
4
|
import {
|
|
4
5
|
getAssetFromKV,
|
|
5
|
-
NotFoundError,
|
|
6
6
|
MethodNotAllowedError,
|
|
7
|
+
NotFoundError,
|
|
7
8
|
serveSinglePageApp,
|
|
8
9
|
} from "@cloudflare/kv-asset-handler";
|
|
10
|
+
import { cacheControl, spaMode } from "config:middleware/serve-static-assets";
|
|
11
|
+
import type { Middleware } from "./common";
|
|
9
12
|
import type { Options } from "@cloudflare/kv-asset-handler";
|
|
10
|
-
import { spaMode, cacheControl } from "config:middleware/serve-static-assets";
|
|
11
13
|
import type * as kvAssetHandler from "@cloudflare/kv-asset-handler";
|
|
12
|
-
import manifest from "__STATIC_CONTENT_MANIFEST";
|
|
13
|
-
const ASSET_MANIFEST = JSON.parse(manifest);
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
const ASSET_MANIFEST = JSON.parse(manifest);
|
|
16
16
|
|
|
17
17
|
const staticAssets: Middleware = async (request, env, _ctx, middlewareCtx) => {
|
|
18
18
|
let options: Partial<Options> = {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
// @ts-ignore entry point will get replaced
|
|
2
2
|
import worker from "__ENTRY_POINT__";
|
|
3
|
+
import { isRoutingRuleMatch } from "./pages-dev-util";
|
|
4
|
+
|
|
3
5
|
// @ts-ignore entry point will get replaced
|
|
4
6
|
export * from "__ENTRY_POINT__";
|
|
5
|
-
import { isRoutingRuleMatch } from "./pages-dev-util";
|
|
6
7
|
|
|
7
8
|
// @ts-ignore routes are injected
|
|
8
9
|
const routes = __ROUTES__;
|
|
@@ -41,14 +41,14 @@ type EventPluginContext<Env, P extends string, Data, PluginArgs> = {
|
|
|
41
41
|
declare type PagesFunction<
|
|
42
42
|
Env = unknown,
|
|
43
43
|
P extends string = string,
|
|
44
|
-
Data extends Record<string, unknown> = Record<string, unknown
|
|
44
|
+
Data extends Record<string, unknown> = Record<string, unknown>,
|
|
45
45
|
> = (context: EventContext<Env, P, Data>) => Response | Promise<Response>;
|
|
46
46
|
|
|
47
47
|
declare type PagesPluginFunction<
|
|
48
48
|
Env = unknown,
|
|
49
49
|
P extends string = string,
|
|
50
50
|
Data extends Record<string, unknown> = Record<string, unknown>,
|
|
51
|
-
PluginArgs = unknown
|
|
51
|
+
PluginArgs = unknown,
|
|
52
52
|
> = (
|
|
53
53
|
context: EventPluginContext<Env, P, Data, PluginArgs>
|
|
54
54
|
) => Response | Promise<Response>;
|
|
@@ -29,7 +29,7 @@ type EventContext<Env, P extends string, Data> = {
|
|
|
29
29
|
declare type PagesFunction<
|
|
30
30
|
Env = unknown,
|
|
31
31
|
P extends string = string,
|
|
32
|
-
Data extends Record<string, unknown> = Record<string, unknown
|
|
32
|
+
Data extends Record<string, unknown> = Record<string, unknown>,
|
|
33
33
|
> = (context: EventContext<Env, P, Data>) => Response | Promise<Response>;
|
|
34
34
|
/* end @cloudflare/workers-types */
|
|
35
35
|
|
|
@@ -5,10 +5,6 @@ import {
|
|
|
5
5
|
DevToolsCommandResponses,
|
|
6
6
|
DevToolsEvent,
|
|
7
7
|
DevToolsEvents,
|
|
8
|
-
type InspectorProxyWorkerIncomingWebSocketMessage,
|
|
9
|
-
type InspectorProxyWorkerOutgoingRequestBody,
|
|
10
|
-
type InspectorProxyWorkerOutgoingWebsocketMessage,
|
|
11
|
-
type ProxyData,
|
|
12
8
|
serialiseError,
|
|
13
9
|
} from "../../src/api/startDevWorker/events";
|
|
14
10
|
import {
|
|
@@ -18,6 +14,12 @@ import {
|
|
|
18
14
|
MaybePromise,
|
|
19
15
|
urlFromParts,
|
|
20
16
|
} from "../../src/api/startDevWorker/utils";
|
|
17
|
+
import type {
|
|
18
|
+
InspectorProxyWorkerIncomingWebSocketMessage,
|
|
19
|
+
InspectorProxyWorkerOutgoingRequestBody,
|
|
20
|
+
InspectorProxyWorkerOutgoingWebsocketMessage,
|
|
21
|
+
ProxyData,
|
|
22
|
+
} from "../../src/api/startDevWorker/events";
|
|
21
23
|
|
|
22
24
|
const ALLOWED_HOST_HOSTNAMES = ["127.0.0.1", "[::1]", "localhost"];
|
|
23
25
|
const ALLOWED_ORIGIN_HOSTNAMES = [
|
|
@@ -58,7 +60,10 @@ function isDevToolsEvent<Method extends DevToolsEvents["method"]>(
|
|
|
58
60
|
}
|
|
59
61
|
|
|
60
62
|
export class InspectorProxyWorker implements DurableObject {
|
|
61
|
-
constructor(
|
|
63
|
+
constructor(
|
|
64
|
+
_state: DurableObjectState,
|
|
65
|
+
readonly env: Env
|
|
66
|
+
) {}
|
|
62
67
|
|
|
63
68
|
websockets: {
|
|
64
69
|
proxyController?: WebSocket;
|
|
@@ -291,6 +296,13 @@ export class InspectorProxyWorker implements DurableObject {
|
|
|
291
296
|
|
|
292
297
|
this.sendDebugLog("NEW RUNTIME WEBSOCKET", runtimeWebSocketUrl);
|
|
293
298
|
|
|
299
|
+
// Make sure DevTools re-fetches script contents,
|
|
300
|
+
// and uses the newly created execution context
|
|
301
|
+
this.sendDevToolsMessage({
|
|
302
|
+
method: "Runtime.executionContextsCleared",
|
|
303
|
+
params: undefined,
|
|
304
|
+
});
|
|
305
|
+
|
|
294
306
|
const upgrade = await fetch(runtimeWebSocketUrl, {
|
|
295
307
|
headers: {
|
|
296
308
|
...this.proxyData.headers,
|