wrangler 0.0.0-c5f3bf45 → 0.0.0-c60fed09
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 +5 -5
- package/bin/wrangler.js +5 -0
- package/package.json +226 -195
- 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 +16 -7
- package/templates/middleware/loader-sw.ts +4 -3
- package/templates/middleware/middleware-ensure-req-body-drained.ts +19 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +1 -0
- package/templates/middleware/middleware-multiworker-dev.ts +37 -28
- package/templates/middleware/middleware-serve-static-assets.ts +5 -5
- package/templates/modules-watch-stub.js +4 -0
- package/templates/pages-dev-pipeline.ts +2 -1
- package/templates/startDevWorker/InspectorProxyWorker.ts +661 -0
- package/templates/startDevWorker/ProxyWorker.ts +326 -0
- package/wrangler-dist/InspectorProxyWorker.js +464 -0
- package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
- package/wrangler-dist/ProxyWorker.js +237 -0
- package/wrangler-dist/ProxyWorker.js.map +6 -0
- package/wrangler-dist/cli.d.ts +22385 -180
- package/wrangler-dist/cli.js +127523 -105965
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/templates/middleware/middleware-d1-beta.ts +0 -244
package/README.md
CHANGED
|
@@ -41,15 +41,15 @@ $ npm install wrangler --save-dev
|
|
|
41
41
|
|
|
42
42
|
Wrangler is configured via a `wrangler.toml` file in the project root. When utilizing the `wrangler init` command, a `wrangler.toml` file will be created for you.
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
Example:
|
|
45
45
|
|
|
46
46
|
```toml
|
|
47
|
-
main = "./src/index.ts" # init w/ TypeScript
|
|
48
47
|
name = "my-worker"
|
|
49
|
-
|
|
48
|
+
main = "./src/index.ts" # init w/ TypeScript
|
|
49
|
+
compatibility_date = "YYYY-MM-DD"
|
|
50
50
|
```
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
For more detailed information about configuration, refer to the [documentation](https://developers.cloudflare.com/workers/wrangler/configuration/).
|
|
53
53
|
|
|
54
54
|
## Commands
|
|
55
55
|
|
|
@@ -65,7 +65,7 @@ Start a local development server, with live reloading and devtools.
|
|
|
65
65
|
|
|
66
66
|
Publish the given script to the worldwide Cloudflare network.
|
|
67
67
|
|
|
68
|
-
For more commands and options, refer to the [documentation](https://developers.cloudflare.com/workers/
|
|
68
|
+
For more commands and options, refer to the [documentation](https://developers.cloudflare.com/workers/wrangler/commands/).
|
|
69
69
|
|
|
70
70
|
## Pages
|
|
71
71
|
|
package/bin/wrangler.js
CHANGED
package/package.json
CHANGED
|
@@ -1,196 +1,227 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
2
|
+
"name": "wrangler",
|
|
3
|
+
"version": "0.0.0-c60fed09",
|
|
4
|
+
"description": "Command-line interface for all things Cloudflare Workers",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"wrangler",
|
|
7
|
+
"cloudflare",
|
|
8
|
+
"workers",
|
|
9
|
+
"cloudflare workers",
|
|
10
|
+
"edge",
|
|
11
|
+
"compute",
|
|
12
|
+
"serverless",
|
|
13
|
+
"serverless application",
|
|
14
|
+
"serverless module",
|
|
15
|
+
"wasm",
|
|
16
|
+
"web",
|
|
17
|
+
"assembly",
|
|
18
|
+
"webassembly",
|
|
19
|
+
"rust",
|
|
20
|
+
"emscripten",
|
|
21
|
+
"typescript",
|
|
22
|
+
"graphql",
|
|
23
|
+
"router",
|
|
24
|
+
"http",
|
|
25
|
+
"cli"
|
|
26
|
+
],
|
|
27
|
+
"homepage": "https://github.com/cloudflare/workers-sdk#readme",
|
|
28
|
+
"bugs": {
|
|
29
|
+
"url": "https://github.com/cloudflare/workers-sdk/issues"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/cloudflare/workers-sdk.git",
|
|
34
|
+
"directory": "packages/wrangler"
|
|
35
|
+
},
|
|
36
|
+
"license": "MIT OR Apache-2.0",
|
|
37
|
+
"author": "wrangler@cloudflare.com",
|
|
38
|
+
"main": "wrangler-dist/cli.js",
|
|
39
|
+
"types": "wrangler-dist/cli.d.ts",
|
|
40
|
+
"bin": {
|
|
41
|
+
"wrangler": "./bin/wrangler.js",
|
|
42
|
+
"wrangler2": "./bin/wrangler.js"
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"bin",
|
|
46
|
+
"miniflare-dist",
|
|
47
|
+
"wrangler-dist",
|
|
48
|
+
"templates",
|
|
49
|
+
"kv-asset-handler.js",
|
|
50
|
+
"Cloudflare_CA.pem"
|
|
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
|
+
"dependencies": {
|
|
86
|
+
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
|
87
|
+
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
|
88
|
+
"blake3-wasm": "^2.1.5",
|
|
89
|
+
"chokidar": "^3.5.3",
|
|
90
|
+
"esbuild": "0.17.19",
|
|
91
|
+
"nanoid": "^3.3.3",
|
|
92
|
+
"path-to-regexp": "^6.2.0",
|
|
93
|
+
"resolve": "^1.22.8",
|
|
94
|
+
"resolve.exports": "^2.0.2",
|
|
95
|
+
"selfsigned": "^2.0.1",
|
|
96
|
+
"source-map": "0.6.1",
|
|
97
|
+
"xxhash-wasm": "^1.0.1",
|
|
98
|
+
"@cloudflare/kv-asset-handler": "0.3.1",
|
|
99
|
+
"miniflare": "3.20240314.0"
|
|
100
|
+
},
|
|
101
|
+
"devDependencies": {
|
|
102
|
+
"@cloudflare/ai": "^1.0.35",
|
|
103
|
+
"@cloudflare/eslint-config-worker": "*",
|
|
104
|
+
"@cloudflare/types": "^6.18.4",
|
|
105
|
+
"@cloudflare/workers-types": "^4.20230914.0",
|
|
106
|
+
"@cspotcode/source-map-support": "0.8.1",
|
|
107
|
+
"@iarna/toml": "^3.0.0",
|
|
108
|
+
"@microsoft/api-extractor": "^7.28.3",
|
|
109
|
+
"@sentry/node": "^7.86.0",
|
|
110
|
+
"@sentry/types": "^7.86.0",
|
|
111
|
+
"@sentry/utils": "^7.86.0",
|
|
112
|
+
"@types/body-parser": "^1.19.2",
|
|
113
|
+
"@types/busboy": "^1.5.0",
|
|
114
|
+
"@types/command-exists": "^1.2.0",
|
|
115
|
+
"@types/express": "^4.17.13",
|
|
116
|
+
"@types/glob-to-regexp": "0.4.1",
|
|
117
|
+
"@types/is-ci": "^3.0.0",
|
|
118
|
+
"@types/javascript-time-ago": "^2.0.3",
|
|
119
|
+
"@types/jest": "^29.5.5",
|
|
120
|
+
"@types/mime": "^2.0.3",
|
|
121
|
+
"@types/minimatch": "^5.1.2",
|
|
122
|
+
"@types/prompts": "^2.0.14",
|
|
123
|
+
"@types/react": "^17.0.37",
|
|
124
|
+
"@types/resolve": "^1.20.6",
|
|
125
|
+
"@types/serve-static": "^1.13.10",
|
|
126
|
+
"@types/shell-quote": "^1.7.2",
|
|
127
|
+
"@types/signal-exit": "^3.0.1",
|
|
128
|
+
"@types/source-map-support": "^0.5.7",
|
|
129
|
+
"@types/supports-color": "^8.1.1",
|
|
130
|
+
"@types/ws": "^8.5.3",
|
|
131
|
+
"@types/yargs": "^17.0.10",
|
|
132
|
+
"@webcontainer/env": "^1.1.0",
|
|
133
|
+
"body-parser": "^1.20.0",
|
|
134
|
+
"chalk": "^2.4.2",
|
|
135
|
+
"cli-table3": "^0.6.3",
|
|
136
|
+
"clipboardy": "^3.0.0",
|
|
137
|
+
"cmd-shim": "^4.1.0",
|
|
138
|
+
"command-exists": "^1.2.9",
|
|
139
|
+
"concurrently": "^7.2.2",
|
|
140
|
+
"devtools-protocol": "^0.0.955664",
|
|
141
|
+
"dotenv": "^16.0.0",
|
|
142
|
+
"esbuild-jest": "0.5.0",
|
|
143
|
+
"execa": "^6.1.0",
|
|
144
|
+
"express": "^4.18.1",
|
|
145
|
+
"finalhandler": "^1.2.0",
|
|
146
|
+
"find-up": "^6.3.0",
|
|
147
|
+
"get-port": "^6.1.2",
|
|
148
|
+
"glob-to-regexp": "0.4.1",
|
|
149
|
+
"http-terminator": "^3.2.0",
|
|
150
|
+
"https-proxy-agent": "7.0.2",
|
|
151
|
+
"ignore": "^5.2.0",
|
|
152
|
+
"ink": "^3.2.0",
|
|
153
|
+
"ink-select-input": "^4.2.1",
|
|
154
|
+
"ink-spinner": "^4.0.3",
|
|
155
|
+
"ink-table": "^3.0.0",
|
|
156
|
+
"ink-testing-library": "^2.1.0",
|
|
157
|
+
"ink-text-input": "^4.0.3",
|
|
158
|
+
"is-ci": "^3.0.1",
|
|
159
|
+
"javascript-time-ago": "^2.5.4",
|
|
160
|
+
"jest": "^29.7.0",
|
|
161
|
+
"jest-fetch-mock": "^3.0.3",
|
|
162
|
+
"jest-websocket-mock": "^2.5.0",
|
|
163
|
+
"mime": "^3.0.0",
|
|
164
|
+
"minimatch": "^5.1.0",
|
|
165
|
+
"msw": "^0.49.1",
|
|
166
|
+
"open": "^8.4.0",
|
|
167
|
+
"p-queue": "^7.2.0",
|
|
168
|
+
"patch-console": "^1.0.0",
|
|
169
|
+
"pretty-bytes": "^6.0.0",
|
|
170
|
+
"prompts": "^2.4.2",
|
|
171
|
+
"react": "^17.0.2",
|
|
172
|
+
"react-error-boundary": "^3.1.4",
|
|
173
|
+
"remove-accents-esm": "^0.0.1",
|
|
174
|
+
"semiver": "^1.1.0",
|
|
175
|
+
"serve-static": "^1.15.0",
|
|
176
|
+
"shell-quote": "^1.8.1",
|
|
177
|
+
"shellac": "^0.8.0",
|
|
178
|
+
"signal-exit": "^3.0.7",
|
|
179
|
+
"strip-ansi": "^7.0.1",
|
|
180
|
+
"supports-color": "^9.2.2",
|
|
181
|
+
"timeago.js": "^4.0.2",
|
|
182
|
+
"ts-dedent": "^2.2.0",
|
|
183
|
+
"undici": "5.28.3",
|
|
184
|
+
"update-check": "^1.5.4",
|
|
185
|
+
"ws": "^8.5.0",
|
|
186
|
+
"xdg-app-paths": "^8.3.0",
|
|
187
|
+
"yargs": "^17.7.2",
|
|
188
|
+
"yoga-layout": "file:../../vendor/yoga-layout-2.0.0-beta.1.tgz",
|
|
189
|
+
"@cloudflare/cli": "1.1.1",
|
|
190
|
+
"@cloudflare/pages-shared": "^0.11.20",
|
|
191
|
+
"@cloudflare/workers-tsconfig": "0.0.0"
|
|
192
|
+
},
|
|
193
|
+
"optionalDependencies": {
|
|
194
|
+
"fsevents": "~2.3.2"
|
|
195
|
+
},
|
|
196
|
+
"peerDependencies": {
|
|
197
|
+
"@cloudflare/workers-types": "^4.20230914.0"
|
|
198
|
+
},
|
|
199
|
+
"peerDependenciesMeta": {
|
|
200
|
+
"@cloudflare/workers-types": {
|
|
201
|
+
"optional": true
|
|
202
|
+
}
|
|
203
|
+
},
|
|
204
|
+
"engines": {
|
|
205
|
+
"node": ">=16.17.0"
|
|
206
|
+
},
|
|
207
|
+
"workers-sdk": {
|
|
208
|
+
"prerelease": true
|
|
209
|
+
},
|
|
210
|
+
"scripts": {
|
|
211
|
+
"assert-git-version": "node -r esbuild-register scripts/assert-git-version.ts",
|
|
212
|
+
"build": "pnpm run clean && pnpm run bundle && pnpm run emit-types",
|
|
213
|
+
"bundle": "node -r esbuild-register scripts/bundle.ts",
|
|
214
|
+
"check:lint": "eslint .",
|
|
215
|
+
"check:type": "tsc",
|
|
216
|
+
"clean": "rimraf wrangler-dist miniflare-dist emitted-types",
|
|
217
|
+
"dev": "pnpm run clean && concurrently -c black,blue --kill-others-on-fail false \"pnpm run bundle --watch\" \"pnpm run check:type --watch --preserveWatchOutput\"",
|
|
218
|
+
"emit-types": "tsc -p tsconfig.emit.json && node -r esbuild-register scripts/emit-types.ts",
|
|
219
|
+
"start": "pnpm run bundle && cross-env NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
|
|
220
|
+
"test": "pnpm run assert-git-version && jest",
|
|
221
|
+
"test:ci": "pnpm run test --coverage",
|
|
222
|
+
"test:debug": "pnpm run test --silent=false --verbose=true",
|
|
223
|
+
"test:e2e": "vitest -c ./e2e/vitest.config.ts",
|
|
224
|
+
"test:watch": "pnpm run test --testTimeout=50000 --watch",
|
|
225
|
+
"type:tests": "tsc -p ./src/__tests__/tsconfig.json && tsc -p ./e2e/tsconfig.json"
|
|
226
|
+
}
|
|
227
|
+
}
|
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;
|
|
@@ -4,15 +4,14 @@
|
|
|
4
4
|
// // through wrangler, or we can potentially let users directly add them as a sort
|
|
5
5
|
// // of "plugin" system.
|
|
6
6
|
|
|
7
|
+
import worker from "__ENTRY_POINT__";
|
|
7
8
|
import {
|
|
8
|
-
Dispatcher,
|
|
9
|
-
Middleware,
|
|
10
9
|
__facade_invoke__,
|
|
11
10
|
__facade_register__,
|
|
11
|
+
Dispatcher,
|
|
12
|
+
Middleware,
|
|
12
13
|
} from "./common";
|
|
13
14
|
|
|
14
|
-
import worker from "__ENTRY_POINT__";
|
|
15
|
-
|
|
16
15
|
// We need to preserve all of the exports from the worker
|
|
17
16
|
export * from "__ENTRY_POINT__";
|
|
18
17
|
|
|
@@ -62,9 +61,11 @@ function getMaskedEnv(rawEnv: unknown) {
|
|
|
62
61
|
*/
|
|
63
62
|
type MissingExportHandlers = Omit<
|
|
64
63
|
Required<ExportedHandler>,
|
|
65
|
-
"tail" | "trace" | "scheduled" | "queue" | "test" | "fetch"
|
|
64
|
+
"tail" | "trace" | "scheduled" | "queue" | "test" | "email" | "fetch"
|
|
66
65
|
>;
|
|
67
66
|
|
|
67
|
+
let registeredMiddleware = false;
|
|
68
|
+
|
|
68
69
|
const facade: ExportedHandler<unknown> & MissingExportHandlers = {
|
|
69
70
|
...(worker.tail && {
|
|
70
71
|
tail: maskHandlerEnv(worker.tail),
|
|
@@ -81,13 +82,21 @@ const facade: ExportedHandler<unknown> & MissingExportHandlers = {
|
|
|
81
82
|
...(worker.test && {
|
|
82
83
|
test: maskHandlerEnv(worker.test),
|
|
83
84
|
}),
|
|
85
|
+
...(worker.email && {
|
|
86
|
+
email: maskHandlerEnv(worker.email),
|
|
87
|
+
}),
|
|
84
88
|
|
|
85
89
|
fetch(request, rawEnv, ctx) {
|
|
86
90
|
const env = getMaskedEnv(rawEnv);
|
|
87
91
|
// Get the chain of middleware from the worker object
|
|
88
92
|
if (worker.middleware && worker.middleware.length > 0) {
|
|
89
|
-
|
|
90
|
-
|
|
93
|
+
// Make sure we only register middleware once:
|
|
94
|
+
// https://github.com/cloudflare/workers-sdk/issues/2386#issuecomment-1614715911
|
|
95
|
+
if (!registeredMiddleware) {
|
|
96
|
+
registeredMiddleware = true;
|
|
97
|
+
for (const middleware of worker.middleware) {
|
|
98
|
+
__facade_register__(middleware);
|
|
99
|
+
}
|
|
91
100
|
}
|
|
92
101
|
|
|
93
102
|
const __facade_modules_dispatch__: Dispatcher = function (type, init) {
|
|
@@ -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,19 @@
|
|
|
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;
|
|
19
|
+
export const wrap = undefined;
|