wrangler 0.0.0-e739b7fe → 0.0.0-e75c5812f
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/bin/wrangler.js +0 -28
- package/config-schema.json +3067 -0
- package/package.json +50 -79
- package/templates/checked-fetch.js +1 -1
- package/templates/facade.d.ts +7 -5
- package/templates/gitignore +3 -0
- package/templates/middleware/loader-modules.ts +92 -94
- package/templates/middleware/middleware-ensure-req-body-drained.ts +0 -1
- package/templates/middleware/middleware-miniflare3-json-error.ts +0 -1
- package/templates/no-op-assets-worker.ts +33 -0
- package/templates/pages-template-plugin.ts +2 -2
- package/templates/pages-template-worker.ts +1 -1
- package/templates/startDevWorker/InspectorProxyWorker.ts +4 -1
- package/templates/startDevWorker/ProxyWorker.ts +35 -25
- package/templates/tsconfig.init.json +4 -87
- package/wrangler-dist/InspectorProxyWorker.js.map +1 -1
- package/wrangler-dist/ProxyWorker.js +28 -24
- package/wrangler-dist/ProxyWorker.js.map +1 -1
- package/wrangler-dist/cli.d.ts +3244 -783
- package/wrangler-dist/cli.js +78327 -37006
- package/Cloudflare_CA.pem +0 -18
- 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-e75c5812f",
|
|
4
4
|
"description": "Command-line interface for all things Cloudflare Workers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wrangler",
|
|
@@ -47,105 +47,71 @@
|
|
|
47
47
|
"wrangler-dist",
|
|
48
48
|
"templates",
|
|
49
49
|
"kv-asset-handler.js",
|
|
50
|
-
"
|
|
50
|
+
"config-schema.json"
|
|
51
51
|
],
|
|
52
|
-
"jest": {
|
|
53
|
-
"coverageReporters": [
|
|
54
|
-
"json",
|
|
55
|
-
"html",
|
|
56
|
-
"text",
|
|
57
|
-
"cobertura"
|
|
58
|
-
],
|
|
59
|
-
"moduleNameMapper": {
|
|
60
|
-
"clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",
|
|
61
|
-
"miniflare/cli": "<rootDir>/../../node_modules/miniflare/dist/src/cli.js"
|
|
62
|
-
},
|
|
63
|
-
"restoreMocks": true,
|
|
64
|
-
"setupFilesAfterEnv": [
|
|
65
|
-
"<rootDir>/src/__tests__/jest.setup.ts"
|
|
66
|
-
],
|
|
67
|
-
"testRegex": "src/__tests__/.*\\.(test|spec)\\.[jt]sx?$",
|
|
68
|
-
"testTimeout": 50000,
|
|
69
|
-
"transform": {
|
|
70
|
-
"^.+\\.c?(t|j)sx?$": [
|
|
71
|
-
"esbuild-jest",
|
|
72
|
-
{
|
|
73
|
-
"sourcemap": true
|
|
74
|
-
}
|
|
75
|
-
]
|
|
76
|
-
},
|
|
77
|
-
"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|strip-ansi|ansi-regex)"
|
|
79
|
-
],
|
|
80
|
-
"snapshotFormat": {
|
|
81
|
-
"escapeString": true,
|
|
82
|
-
"printBasicPrototype": true
|
|
83
|
-
}
|
|
84
|
-
},
|
|
85
52
|
"dependencies": {
|
|
86
53
|
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
|
87
54
|
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
|
88
55
|
"blake3-wasm": "^2.1.5",
|
|
89
56
|
"chokidar": "^3.5.3",
|
|
57
|
+
"date-fns": "^3.6.0",
|
|
90
58
|
"esbuild": "0.17.19",
|
|
91
59
|
"nanoid": "^3.3.3",
|
|
92
60
|
"path-to-regexp": "^6.2.0",
|
|
93
61
|
"resolve": "^1.22.8",
|
|
94
62
|
"resolve.exports": "^2.0.2",
|
|
95
63
|
"selfsigned": "^2.0.1",
|
|
96
|
-
"source-map": "0.6.1",
|
|
64
|
+
"source-map": "^0.6.1",
|
|
65
|
+
"unenv": "npm:unenv-nightly@1.10.0-1717606461.a117952",
|
|
66
|
+
"workerd": "1.20240806.0",
|
|
97
67
|
"xxhash-wasm": "^1.0.1",
|
|
98
|
-
"@cloudflare/
|
|
99
|
-
"miniflare": "3.
|
|
68
|
+
"@cloudflare/workers-shared": "0.0.0-e75c5812f",
|
|
69
|
+
"miniflare": "3.20240806.1",
|
|
70
|
+
"@cloudflare/kv-asset-handler": "0.3.4"
|
|
100
71
|
},
|
|
101
72
|
"devDependencies": {
|
|
102
|
-
"@cloudflare/ai": "^1.0.35",
|
|
103
|
-
"@cloudflare/eslint-config-worker": "*",
|
|
104
73
|
"@cloudflare/types": "^6.18.4",
|
|
105
|
-
"@cloudflare/workers-types": "^4.
|
|
74
|
+
"@cloudflare/workers-types": "^4.20240806.0",
|
|
106
75
|
"@cspotcode/source-map-support": "0.8.1",
|
|
107
76
|
"@iarna/toml": "^3.0.0",
|
|
108
|
-
"@microsoft/api-extractor": "^7.
|
|
77
|
+
"@microsoft/api-extractor": "^7.47.0",
|
|
109
78
|
"@sentry/node": "^7.86.0",
|
|
110
79
|
"@sentry/types": "^7.86.0",
|
|
111
80
|
"@sentry/utils": "^7.86.0",
|
|
112
81
|
"@types/body-parser": "^1.19.2",
|
|
113
|
-
"@types/busboy": "^1.5.0",
|
|
114
82
|
"@types/command-exists": "^1.2.0",
|
|
115
83
|
"@types/express": "^4.17.13",
|
|
116
|
-
"@types/glob-to-regexp": "0.4.1",
|
|
84
|
+
"@types/glob-to-regexp": "^0.4.1",
|
|
117
85
|
"@types/is-ci": "^3.0.0",
|
|
118
86
|
"@types/javascript-time-ago": "^2.0.3",
|
|
119
|
-
"@types/
|
|
120
|
-
"@types/mime": "^2.0.3",
|
|
87
|
+
"@types/mime": "^3.0.4",
|
|
121
88
|
"@types/minimatch": "^5.1.2",
|
|
122
89
|
"@types/prompts": "^2.0.14",
|
|
123
|
-
"@types/react": "^
|
|
90
|
+
"@types/react": "^18.3.3",
|
|
124
91
|
"@types/resolve": "^1.20.6",
|
|
125
92
|
"@types/serve-static": "^1.13.10",
|
|
126
93
|
"@types/shell-quote": "^1.7.2",
|
|
127
94
|
"@types/signal-exit": "^3.0.1",
|
|
128
|
-
"@types/source-map-support": "^0.5.7",
|
|
129
95
|
"@types/supports-color": "^8.1.1",
|
|
130
|
-
"@types/ws": "^8.5.
|
|
131
|
-
"@types/yargs": "^17.0.
|
|
96
|
+
"@types/ws": "^8.5.7",
|
|
97
|
+
"@types/yargs": "^17.0.22",
|
|
98
|
+
"@vitest/ui": "^1.6.0",
|
|
132
99
|
"@webcontainer/env": "^1.1.0",
|
|
133
100
|
"body-parser": "^1.20.0",
|
|
134
|
-
"chalk": "^2.
|
|
101
|
+
"chalk": "^5.2.0",
|
|
135
102
|
"cli-table3": "^0.6.3",
|
|
136
103
|
"clipboardy": "^3.0.0",
|
|
137
104
|
"cmd-shim": "^4.1.0",
|
|
138
105
|
"command-exists": "^1.2.9",
|
|
139
|
-
"concurrently": "^
|
|
140
|
-
"devtools-protocol": "^0.0.
|
|
106
|
+
"concurrently": "^8.2.2",
|
|
107
|
+
"devtools-protocol": "^0.0.1182435",
|
|
141
108
|
"dotenv": "^16.0.0",
|
|
142
|
-
"
|
|
109
|
+
"es-module-lexer": "^1.3.0",
|
|
143
110
|
"execa": "^6.1.0",
|
|
144
111
|
"express": "^4.18.1",
|
|
145
|
-
"finalhandler": "^1.2.0",
|
|
146
112
|
"find-up": "^6.3.0",
|
|
147
|
-
"get-port": "^
|
|
148
|
-
"glob-to-regexp": "0.4.1",
|
|
113
|
+
"get-port": "^7.0.0",
|
|
114
|
+
"glob-to-regexp": "^0.4.1",
|
|
149
115
|
"http-terminator": "^3.2.0",
|
|
150
116
|
"https-proxy-agent": "7.0.2",
|
|
151
117
|
"ignore": "^5.2.0",
|
|
@@ -153,74 +119,79 @@
|
|
|
153
119
|
"ink-select-input": "^4.2.1",
|
|
154
120
|
"ink-spinner": "^4.0.3",
|
|
155
121
|
"ink-table": "^3.0.0",
|
|
156
|
-
"ink-testing-library": "^2.1.0",
|
|
157
|
-
"ink-text-input": "^4.0.3",
|
|
158
122
|
"is-ci": "^3.0.1",
|
|
159
123
|
"javascript-time-ago": "^2.5.4",
|
|
160
|
-
"
|
|
161
|
-
"jest-fetch-mock": "^3.0.3",
|
|
162
|
-
"jest-websocket-mock": "^2.5.0",
|
|
124
|
+
"md5-file": "5.0.0",
|
|
163
125
|
"mime": "^3.0.0",
|
|
164
126
|
"minimatch": "^5.1.0",
|
|
165
|
-
"
|
|
127
|
+
"mock-socket": "^9.3.1",
|
|
128
|
+
"msw": "^2.3.0",
|
|
166
129
|
"open": "^8.4.0",
|
|
167
130
|
"p-queue": "^7.2.0",
|
|
168
131
|
"patch-console": "^1.0.0",
|
|
169
132
|
"pretty-bytes": "^6.0.0",
|
|
170
133
|
"prompts": "^2.4.2",
|
|
171
|
-
"
|
|
134
|
+
"ps-list": "^8.1.1",
|
|
135
|
+
"react": "^18.3.1",
|
|
172
136
|
"react-error-boundary": "^3.1.4",
|
|
173
|
-
"remove-accents-esm": "^0.0.1",
|
|
174
137
|
"semiver": "^1.1.0",
|
|
175
138
|
"serve-static": "^1.15.0",
|
|
176
139
|
"shell-quote": "^1.8.1",
|
|
177
140
|
"shellac": "^0.8.0",
|
|
178
141
|
"signal-exit": "^3.0.7",
|
|
179
|
-
"strip-ansi": "^7.0
|
|
142
|
+
"strip-ansi": "^7.1.0",
|
|
180
143
|
"supports-color": "^9.2.2",
|
|
181
144
|
"timeago.js": "^4.0.2",
|
|
182
145
|
"ts-dedent": "^2.2.0",
|
|
183
|
-
"
|
|
146
|
+
"ts-json-schema-generator": "^1.5.0",
|
|
147
|
+
"undici": "^5.28.4",
|
|
184
148
|
"update-check": "^1.5.4",
|
|
185
|
-
"
|
|
149
|
+
"vitest": "^1.6.0",
|
|
150
|
+
"vitest-websocket-mock": "^0.3.0",
|
|
151
|
+
"ws": "^8.17.1",
|
|
186
152
|
"xdg-app-paths": "^8.3.0",
|
|
187
153
|
"yargs": "^17.7.2",
|
|
188
154
|
"yoga-layout": "file:../../vendor/yoga-layout-2.0.0-beta.1.tgz",
|
|
155
|
+
"@cloudflare/pages-shared": "^0.11.52",
|
|
156
|
+
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
189
157
|
"@cloudflare/cli": "1.1.1",
|
|
190
|
-
"@cloudflare/
|
|
191
|
-
"@cloudflare/workers-tsconfig": "0.0.0"
|
|
192
|
-
},
|
|
193
|
-
"optionalDependencies": {
|
|
194
|
-
"fsevents": "~2.3.2"
|
|
158
|
+
"@cloudflare/eslint-config-worker": "1.1.0"
|
|
195
159
|
},
|
|
196
160
|
"peerDependencies": {
|
|
197
|
-
"@cloudflare/workers-types": "^4.
|
|
161
|
+
"@cloudflare/workers-types": "^4.20240806.0"
|
|
198
162
|
},
|
|
199
163
|
"peerDependenciesMeta": {
|
|
200
164
|
"@cloudflare/workers-types": {
|
|
201
165
|
"optional": true
|
|
202
166
|
}
|
|
203
167
|
},
|
|
168
|
+
"optionalDependencies": {
|
|
169
|
+
"fsevents": "~2.3.2"
|
|
170
|
+
},
|
|
204
171
|
"engines": {
|
|
205
172
|
"node": ">=16.17.0"
|
|
206
173
|
},
|
|
174
|
+
"volta": {
|
|
175
|
+
"extends": "../../package.json"
|
|
176
|
+
},
|
|
207
177
|
"workers-sdk": {
|
|
208
178
|
"prerelease": true
|
|
209
179
|
},
|
|
210
180
|
"scripts": {
|
|
211
181
|
"assert-git-version": "node -r esbuild-register scripts/assert-git-version.ts",
|
|
212
|
-
"build": "pnpm run clean && pnpm run bundle && pnpm run emit-types",
|
|
182
|
+
"build": "pnpm run clean && pnpm run bundle && pnpm run emit-types && pnpm run generate-json-schema",
|
|
213
183
|
"bundle": "node -r esbuild-register scripts/bundle.ts",
|
|
214
|
-
"check:lint": "eslint .",
|
|
184
|
+
"check:lint": "eslint . --max-warnings=0",
|
|
215
185
|
"check:type": "tsc",
|
|
216
186
|
"clean": "rimraf wrangler-dist miniflare-dist emitted-types",
|
|
217
187
|
"dev": "pnpm run clean && concurrently -c black,blue --kill-others-on-fail false \"pnpm run bundle --watch\" \"pnpm run check:type --watch --preserveWatchOutput\"",
|
|
218
188
|
"emit-types": "tsc -p tsconfig.emit.json && node -r esbuild-register scripts/emit-types.ts",
|
|
189
|
+
"generate-json-schema": "pnpm exec ts-json-schema-generator --no-type-check --path src/config/config.ts --type RawConfig --out config-schema.json",
|
|
219
190
|
"start": "pnpm run bundle && cross-env NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
|
|
220
|
-
"test": "pnpm run assert-git-version &&
|
|
221
|
-
"test:ci": "pnpm run test
|
|
191
|
+
"test": "pnpm run assert-git-version && vitest",
|
|
192
|
+
"test:ci": "pnpm run test run",
|
|
222
193
|
"test:debug": "pnpm run test --silent=false --verbose=true",
|
|
223
|
-
"test:e2e": "vitest -c ./e2e/vitest.config.
|
|
194
|
+
"test:e2e": "vitest -c ./e2e/vitest.config.mts",
|
|
224
195
|
"test:watch": "pnpm run test --testTimeout=50000 --watch",
|
|
225
196
|
"type:tests": "tsc -p ./src/__tests__/tsconfig.json && tsc -p ./e2e/tsconfig.json"
|
|
226
197
|
}
|
package/templates/facade.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
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
|
+
|
|
7
|
+
const worker: ExportedHandler | WorkerEntrypointConstructor;
|
|
7
8
|
export default worker;
|
|
9
|
+
export const __INTERNAL_WRANGLER_MIDDLEWARE__: Middleware[];
|
|
8
10
|
}
|
|
9
11
|
|
|
10
12
|
declare module "__KV_ASSET_HANDLER__" {
|
package/templates/gitignore
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
// // of "plugin" system.
|
|
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.
|
|
6
5
|
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
__facade_register__,
|
|
11
|
-
Dispatcher,
|
|
12
|
-
Middleware,
|
|
13
|
-
} from "./common";
|
|
6
|
+
import ENTRY, { __INTERNAL_WRANGLER_MIDDLEWARE__ } from "__ENTRY_POINT__";
|
|
7
|
+
import { __facade_invoke__, __facade_register__, Dispatcher } from "./common";
|
|
8
|
+
import type { WorkerEntrypointConstructor } from "__ENTRY_POINT__";
|
|
14
9
|
|
|
15
|
-
//
|
|
10
|
+
// Preserve all the exports from the worker
|
|
16
11
|
export * from "__ENTRY_POINT__";
|
|
17
12
|
|
|
18
13
|
class __Facade_ScheduledController__ implements ScheduledController {
|
|
19
|
-
#noRetry: ScheduledController["noRetry"];
|
|
14
|
+
readonly #noRetry: ScheduledController["noRetry"];
|
|
20
15
|
|
|
21
16
|
constructor(
|
|
22
17
|
readonly scheduledTime: number,
|
|
@@ -35,71 +30,34 @@ class __Facade_ScheduledController__ implements ScheduledController {
|
|
|
35
30
|
}
|
|
36
31
|
}
|
|
37
32
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
let env = rawEnv as Record<string, unknown>;
|
|
50
|
-
if (worker.envWrappers && worker.envWrappers.length > 0) {
|
|
51
|
-
for (const wrapFn of worker.envWrappers) {
|
|
52
|
-
env = wrapFn(env);
|
|
53
|
-
}
|
|
33
|
+
function wrapExportedHandler(worker: ExportedHandler): ExportedHandler {
|
|
34
|
+
// If we don't have any middleware defined, just return the handler as is
|
|
35
|
+
if (
|
|
36
|
+
__INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
|
|
37
|
+
__INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
|
|
38
|
+
) {
|
|
39
|
+
return worker;
|
|
40
|
+
}
|
|
41
|
+
// Otherwise, register all middleware once
|
|
42
|
+
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
|
|
43
|
+
__facade_register__(middleware);
|
|
54
44
|
}
|
|
55
|
-
return env;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* This type is here to cause a type error if a new export handler is added to
|
|
60
|
-
* `ExportHandler` without it being included in the `facade` below.
|
|
61
|
-
*/
|
|
62
|
-
type MissingExportHandlers = Omit<
|
|
63
|
-
Required<ExportedHandler>,
|
|
64
|
-
"tail" | "trace" | "scheduled" | "queue" | "test" | "email" | "fetch"
|
|
65
|
-
>;
|
|
66
|
-
|
|
67
|
-
let registeredMiddleware = false;
|
|
68
|
-
|
|
69
|
-
const facade: ExportedHandler<unknown> & MissingExportHandlers = {
|
|
70
|
-
...(worker.tail && {
|
|
71
|
-
tail: maskHandlerEnv(worker.tail),
|
|
72
|
-
}),
|
|
73
|
-
...(worker.trace && {
|
|
74
|
-
trace: maskHandlerEnv(worker.trace),
|
|
75
|
-
}),
|
|
76
|
-
...(worker.scheduled && {
|
|
77
|
-
scheduled: maskHandlerEnv(worker.scheduled),
|
|
78
|
-
}),
|
|
79
|
-
...(worker.queue && {
|
|
80
|
-
queue: maskHandlerEnv(worker.queue),
|
|
81
|
-
}),
|
|
82
|
-
...(worker.test && {
|
|
83
|
-
test: maskHandlerEnv(worker.test),
|
|
84
|
-
}),
|
|
85
|
-
...(worker.email && {
|
|
86
|
-
email: maskHandlerEnv(worker.email),
|
|
87
|
-
}),
|
|
88
45
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
}
|
|
46
|
+
const fetchDispatcher: ExportedHandlerFetchHandler = function (
|
|
47
|
+
request,
|
|
48
|
+
env,
|
|
49
|
+
ctx
|
|
50
|
+
) {
|
|
51
|
+
if (worker.fetch === undefined) {
|
|
52
|
+
throw new Error("Handler does not export a fetch() function.");
|
|
53
|
+
}
|
|
54
|
+
return worker.fetch(request, env, ctx);
|
|
55
|
+
};
|
|
101
56
|
|
|
102
|
-
|
|
57
|
+
return {
|
|
58
|
+
...worker,
|
|
59
|
+
fetch(request, env, ctx) {
|
|
60
|
+
const dispatcher: Dispatcher = function (type, init) {
|
|
103
61
|
if (type === "scheduled" && worker.scheduled !== undefined) {
|
|
104
62
|
const controller = new __Facade_ScheduledController__(
|
|
105
63
|
Date.now(),
|
|
@@ -109,28 +67,68 @@ const facade: ExportedHandler<unknown> & MissingExportHandlers = {
|
|
|
109
67
|
return worker.scheduled(controller, env, ctx);
|
|
110
68
|
}
|
|
111
69
|
};
|
|
70
|
+
return __facade_invoke__(request, env, ctx, dispatcher, fetchDispatcher);
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function wrapWorkerEntrypoint(
|
|
76
|
+
klass: WorkerEntrypointConstructor
|
|
77
|
+
): WorkerEntrypointConstructor {
|
|
78
|
+
// If we don't have any middleware defined, just return the handler as is
|
|
79
|
+
if (
|
|
80
|
+
__INTERNAL_WRANGLER_MIDDLEWARE__ === undefined ||
|
|
81
|
+
__INTERNAL_WRANGLER_MIDDLEWARE__.length === 0
|
|
82
|
+
) {
|
|
83
|
+
return klass;
|
|
84
|
+
}
|
|
85
|
+
// Otherwise, register all middleware once
|
|
86
|
+
for (const middleware of __INTERNAL_WRANGLER_MIDDLEWARE__) {
|
|
87
|
+
__facade_register__(middleware);
|
|
88
|
+
}
|
|
112
89
|
|
|
90
|
+
// `extend`ing `klass` here so other RPC methods remain callable
|
|
91
|
+
return class extends klass {
|
|
92
|
+
#fetchDispatcher: ExportedHandlerFetchHandler<Record<string, unknown>> = (
|
|
93
|
+
request,
|
|
94
|
+
env,
|
|
95
|
+
ctx
|
|
96
|
+
) => {
|
|
97
|
+
this.env = env;
|
|
98
|
+
this.ctx = ctx;
|
|
99
|
+
if (super.fetch === undefined) {
|
|
100
|
+
throw new Error("Entrypoint class does not define a fetch() function.");
|
|
101
|
+
}
|
|
102
|
+
return super.fetch(request);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
#dispatcher: Dispatcher = (type, init) => {
|
|
106
|
+
if (type === "scheduled" && super.scheduled !== undefined) {
|
|
107
|
+
const controller = new __Facade_ScheduledController__(
|
|
108
|
+
Date.now(),
|
|
109
|
+
init.cron ?? "",
|
|
110
|
+
() => {}
|
|
111
|
+
);
|
|
112
|
+
return super.scheduled(controller);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
fetch(request: Request<unknown, IncomingRequestCfProperties>) {
|
|
113
117
|
return __facade_invoke__(
|
|
114
118
|
request,
|
|
115
|
-
env,
|
|
116
|
-
ctx,
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
this.env,
|
|
120
|
+
this.ctx,
|
|
121
|
+
this.#dispatcher,
|
|
122
|
+
this.#fetchDispatcher
|
|
119
123
|
);
|
|
120
|
-
} else {
|
|
121
|
-
// We didn't have any middleware so we can skip the invocation chain,
|
|
122
|
-
// and just call the fetch handler directly
|
|
123
|
-
|
|
124
|
-
// We "don't care" if this is undefined as we want to have the same behavior
|
|
125
|
-
// as if the worker completely bypassed middleware.
|
|
126
|
-
return __facade_modules_fetch__(request, env, ctx);
|
|
127
124
|
}
|
|
128
|
-
}
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
type HandlerFn<D, R> = (data: D, env: unknown, ctx: ExecutionContext) => R;
|
|
132
|
-
function maskHandlerEnv<D, R>(handler: HandlerFn<D, R>): HandlerFn<D, R> {
|
|
133
|
-
return (data, env, ctx) => handler(data, getMaskedEnv(env), ctx);
|
|
125
|
+
};
|
|
134
126
|
}
|
|
135
127
|
|
|
136
|
-
|
|
128
|
+
let WRAPPED_ENTRY: ExportedHandler | WorkerEntrypointConstructor | undefined;
|
|
129
|
+
if (typeof ENTRY === "object") {
|
|
130
|
+
WRAPPED_ENTRY = wrapExportedHandler(ENTRY);
|
|
131
|
+
} else if (typeof ENTRY === "function") {
|
|
132
|
+
WRAPPED_ENTRY = wrapWorkerEntrypoint(ENTRY);
|
|
133
|
+
}
|
|
134
|
+
export default WRAPPED_ENTRY;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This Worker is used as a default entry-point for Assets-only
|
|
3
|
+
* Workers. It proxies the request directly on to the Asset Sever
|
|
4
|
+
* Worker service binding.
|
|
5
|
+
*
|
|
6
|
+
* In an Assets-only Workers world, we want to enable users
|
|
7
|
+
* to deploy a Worker with Assets without ever having to provide
|
|
8
|
+
* a User Worker.
|
|
9
|
+
*
|
|
10
|
+
* ```bash
|
|
11
|
+
* wrangler dev --experimental-assets dist
|
|
12
|
+
* wrangler deploy --experimental-assets dist
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* ```toml
|
|
16
|
+
* name = "assets-only-worker"
|
|
17
|
+
* compatibility_date = "2024-01-01"
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* Without a user-defined Worker, which usually serves as the entry
|
|
21
|
+
* point in the bundling process, wrangler needs to default to some
|
|
22
|
+
* other entry-point Worker for all intents and purposes. This is what
|
|
23
|
+
* this Worker is.
|
|
24
|
+
*/
|
|
25
|
+
type Env = {
|
|
26
|
+
ASSET_SERVER: Fetcher;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default {
|
|
30
|
+
async fetch(request: Request, env: Env) {
|
|
31
|
+
return env.ASSET_SERVER.fetch(request);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
@@ -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
|
|
|
@@ -60,7 +60,10 @@ function isDevToolsEvent<Method extends DevToolsEvents["method"]>(
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
export class InspectorProxyWorker implements DurableObject {
|
|
63
|
-
constructor(
|
|
63
|
+
constructor(
|
|
64
|
+
_state: DurableObjectState,
|
|
65
|
+
readonly env: Env
|
|
66
|
+
) {}
|
|
64
67
|
|
|
65
68
|
websockets: {
|
|
66
69
|
proxyController?: WebSocket;
|
|
@@ -33,7 +33,10 @@ export default {
|
|
|
33
33
|
} as ExportedHandler<Env, unknown, ProxyWorkerIncomingRequestBody>;
|
|
34
34
|
|
|
35
35
|
export class ProxyWorker implements DurableObject {
|
|
36
|
-
constructor(
|
|
36
|
+
constructor(
|
|
37
|
+
readonly state: DurableObjectState,
|
|
38
|
+
readonly env: Env
|
|
39
|
+
) {}
|
|
37
40
|
|
|
38
41
|
proxyData?: ProxyData;
|
|
39
42
|
requestQueue = new Map<Request, DeferredPromise<Response>>();
|
|
@@ -121,11 +124,18 @@ export class ProxyWorker implements DurableObject {
|
|
|
121
124
|
Object.assign(userWorkerUrl, proxyData.userWorkerUrl);
|
|
122
125
|
|
|
123
126
|
// set request.url in the UserWorker
|
|
124
|
-
const innerUrl =
|
|
125
|
-
|
|
127
|
+
const innerUrl = urlFromParts(
|
|
128
|
+
proxyData.userWorkerInnerUrlOverrides ?? {},
|
|
129
|
+
request.url
|
|
130
|
+
);
|
|
126
131
|
headers.set("MF-Original-URL", innerUrl.href);
|
|
127
132
|
headers.set("MF-Disable-Pretty-Error", "true"); // disables the UserWorker miniflare instance from rendering the pretty error -- instead the ProxyWorker miniflare instance will intercept the json error response and render the pretty error page
|
|
128
133
|
|
|
134
|
+
// Preserve client `Accept-Encoding`, rather than using Worker's default
|
|
135
|
+
// of `Accept-Encoding: br, gzip`
|
|
136
|
+
const encoding = request.cf?.clientAcceptEncoding;
|
|
137
|
+
if (encoding !== undefined) headers.set("Accept-Encoding", encoding);
|
|
138
|
+
|
|
129
139
|
rewriteUrlRelatedHeaders(headers, outerUrl, innerUrl);
|
|
130
140
|
|
|
131
141
|
// merge proxyData headers with the request headers
|
|
@@ -268,28 +278,7 @@ function insertLiveReloadScript(
|
|
|
268
278
|
websocketUrl.protocol =
|
|
269
279
|
websocketUrl.protocol === "http:" ? "ws:" : "wss:";
|
|
270
280
|
|
|
271
|
-
end.append(
|
|
272
|
-
`
|
|
273
|
-
<script>
|
|
274
|
-
(function() {
|
|
275
|
-
var ws;
|
|
276
|
-
function recover() {
|
|
277
|
-
ws = null;
|
|
278
|
-
setTimeout(initLiveReload, 100);
|
|
279
|
-
}
|
|
280
|
-
function initLiveReload() {
|
|
281
|
-
if (ws) return;
|
|
282
|
-
var origin = (location.protocol === "http:" ? "ws://" : "wss://") + location.host;
|
|
283
|
-
ws = new WebSocket(origin + "/cdn-cgi/live-reload", "${LIVE_RELOAD_PROTOCOL}");
|
|
284
|
-
ws.onclose = recover;
|
|
285
|
-
ws.onerror = recover;
|
|
286
|
-
ws.onmessage = location.reload.bind(location);
|
|
287
|
-
}
|
|
288
|
-
})();
|
|
289
|
-
</script>
|
|
290
|
-
`,
|
|
291
|
-
{ html: true }
|
|
292
|
-
);
|
|
281
|
+
end.append(liveReloadScript, { html: true });
|
|
293
282
|
}
|
|
294
283
|
},
|
|
295
284
|
});
|
|
@@ -297,6 +286,27 @@ function insertLiveReloadScript(
|
|
|
297
286
|
return htmlRewriter.transform(response);
|
|
298
287
|
}
|
|
299
288
|
|
|
289
|
+
const liveReloadScript = `
|
|
290
|
+
<script defer type="application/javascript">
|
|
291
|
+
(function() {
|
|
292
|
+
var ws;
|
|
293
|
+
function recover() {
|
|
294
|
+
ws = null;
|
|
295
|
+
setTimeout(initLiveReload, 100);
|
|
296
|
+
}
|
|
297
|
+
function initLiveReload() {
|
|
298
|
+
if (ws) return;
|
|
299
|
+
var origin = (location.protocol === "http:" ? "ws://" : "wss://") + location.host;
|
|
300
|
+
ws = new WebSocket(origin + "/cdn-cgi/live-reload", "${LIVE_RELOAD_PROTOCOL}");
|
|
301
|
+
ws.onclose = recover;
|
|
302
|
+
ws.onerror = recover;
|
|
303
|
+
ws.onmessage = location.reload.bind(location);
|
|
304
|
+
}
|
|
305
|
+
initLiveReload();
|
|
306
|
+
})();
|
|
307
|
+
</script>
|
|
308
|
+
`;
|
|
309
|
+
|
|
300
310
|
/**
|
|
301
311
|
* Rewrite references to URLs in request/response headers.
|
|
302
312
|
*
|