wrangler 0.0.0-e2f9bb2 → 0.0.0-e322475
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/Cloudflare_CA.pem +18 -0
- package/README.md +3 -1
- package/bin/wrangler.js +36 -4
- package/kv-asset-handler.js +1 -0
- package/package.json +15 -7
- package/pages/functions/buildPlugin.ts +13 -0
- package/pages/functions/buildWorker.ts +14 -1
- package/pages/functions/template-plugin.ts +3 -2
- package/src/__tests__/configuration.test.ts +652 -229
- package/src/__tests__/dev.test.tsx +372 -79
- package/src/__tests__/helpers/mock-cfetch.ts +2 -2
- package/src/__tests__/helpers/mock-console.ts +11 -1
- package/src/__tests__/helpers/mock-dialogs.ts +75 -11
- package/src/__tests__/helpers/mock-process.ts +24 -0
- package/src/__tests__/index.test.ts +81 -72
- package/src/__tests__/init.test.ts +1360 -410
- package/src/__tests__/jest.setup.ts +38 -0
- package/src/__tests__/kv.test.ts +218 -152
- package/src/__tests__/logger.test.ts +26 -0
- package/src/__tests__/package-manager.test.ts +154 -7
- package/src/__tests__/pages.test.ts +478 -53
- package/src/__tests__/parse.test.ts +8 -0
- package/src/__tests__/publish.test.ts +1614 -333
- package/src/__tests__/r2.test.ts +55 -36
- package/src/__tests__/secret.test.ts +39 -4
- package/src/__tests__/user.test.ts +1 -0
- package/src/__tests__/whoami.test.tsx +34 -0
- package/src/abort.d.ts +3 -0
- package/src/bundle-reporter.tsx +29 -0
- package/src/bundle.ts +42 -7
- package/src/cfetch/index.ts +21 -4
- package/src/cfetch/internal.ts +25 -20
- package/src/config/config.ts +11 -2
- package/src/config/environment.ts +41 -15
- package/src/config/index.ts +162 -0
- package/src/config/validation-helpers.ts +10 -1
- package/src/config/validation.ts +234 -78
- package/src/create-worker-preview.ts +32 -22
- package/src/create-worker-upload-form.ts +22 -8
- package/src/dev/dev.tsx +48 -67
- package/src/dev/local.tsx +16 -7
- package/src/dev/remote.tsx +57 -21
- package/src/dev/use-esbuild.ts +1 -7
- package/src/dialogs.tsx +48 -0
- package/src/durable.ts +102 -0
- package/src/entry.ts +71 -10
- package/src/generate-auth-url.ts +33 -0
- package/src/generate-random-state.ts +16 -0
- package/src/git-client.ts +42 -0
- package/src/index.tsx +619 -338
- package/src/inspect.ts +39 -0
- package/src/kv.ts +116 -27
- package/src/logger.ts +8 -1
- package/src/open-in-browser.ts +3 -12
- package/src/package-manager.ts +50 -3
- package/src/pages.tsx +434 -207
- package/src/parse.ts +44 -5
- package/src/proxy.ts +66 -44
- package/src/publish.ts +407 -137
- package/src/sites.tsx +103 -28
- package/src/user.tsx +35 -26
- package/src/whoami.tsx +3 -2
- package/src/worker.ts +10 -1
- package/src/zones.ts +73 -0
- package/templates/new-worker-scheduled.js +17 -0
- package/templates/new-worker-scheduled.ts +32 -0
- package/templates/new-worker.ts +16 -1
- package/templates/no-op-worker.js +10 -0
- package/templates/static-asset-facade.js +2 -6
- package/wrangler-dist/cli.js +46122 -32396
- package/vendor/@cloudflare/kv-asset-handler/CHANGELOG.md +0 -332
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_APACHE +0 -176
- package/vendor/@cloudflare/kv-asset-handler/LICENSE_MIT +0 -25
- package/vendor/@cloudflare/kv-asset-handler/README.md +0 -245
- package/vendor/@cloudflare/kv-asset-handler/dist/index.d.ts +0 -32
- package/vendor/@cloudflare/kv-asset-handler/dist/index.js +0 -354
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.d.ts +0 -13
- package/vendor/@cloudflare/kv-asset-handler/dist/mocks.js +0 -148
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/getAssetFromKV.js +0 -436
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/mapRequestToAsset.js +0 -40
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.d.ts +0 -1
- package/vendor/@cloudflare/kv-asset-handler/dist/test/serveSinglePageApp.js +0 -42
- package/vendor/@cloudflare/kv-asset-handler/dist/types.d.ts +0 -26
- package/vendor/@cloudflare/kv-asset-handler/dist/types.js +0 -31
- package/vendor/@cloudflare/kv-asset-handler/package.json +0 -52
- package/vendor/@cloudflare/kv-asset-handler/src/index.ts +0 -296
- package/vendor/@cloudflare/kv-asset-handler/src/mocks.ts +0 -136
- package/vendor/@cloudflare/kv-asset-handler/src/test/getAssetFromKV.ts +0 -464
- package/vendor/@cloudflare/kv-asset-handler/src/test/mapRequestToAsset.ts +0 -33
- package/vendor/@cloudflare/kv-asset-handler/src/test/serveSinglePageApp.ts +0 -42
- package/vendor/@cloudflare/kv-asset-handler/src/types.ts +0 -39
- package/vendor/wrangler-mime/CHANGELOG.md +0 -289
- package/vendor/wrangler-mime/LICENSE +0 -21
- package/vendor/wrangler-mime/Mime.js +0 -97
- package/vendor/wrangler-mime/README.md +0 -187
- package/vendor/wrangler-mime/cli.js +0 -46
- package/vendor/wrangler-mime/index.js +0 -4
- package/vendor/wrangler-mime/lite.js +0 -4
- package/vendor/wrangler-mime/package.json +0 -52
- package/vendor/wrangler-mime/types/other.js +0 -1
- package/vendor/wrangler-mime/types/standard.js +0 -1
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
|
2
|
+
MIIC6zCCAkygAwIBAgIUI7b68p0pPrCBoW4ptlyvVcPItscwCgYIKoZIzj0EAwQw
|
|
3
|
+
gY0xCzAJBgNVBAYTAlVTMRMwEQYDVQQIEwpDYWxpZm9ybmlhMRYwFAYDVQQHEw1T
|
|
4
|
+
YW4gRnJhbmNpc2NvMRgwFgYDVQQKEw9DbG91ZGZsYXJlLCBJbmMxNzA1BgNVBAMT
|
|
5
|
+
LkNsb3VkZmxhcmUgZm9yIFRlYW1zIEVDQyBDZXJ0aWZpY2F0ZSBBdXRob3JpdHkw
|
|
6
|
+
HhcNMjAwMjA0MTYwNTAwWhcNMjUwMjAyMTYwNTAwWjCBjTELMAkGA1UEBhMCVVMx
|
|
7
|
+
EzARBgNVBAgTCkNhbGlmb3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xGDAW
|
|
8
|
+
BgNVBAoTD0Nsb3VkZmxhcmUsIEluYzE3MDUGA1UEAxMuQ2xvdWRmbGFyZSBmb3Ig
|
|
9
|
+
VGVhbXMgRUNDIENlcnRpZmljYXRlIEF1dGhvcml0eTCBmzAQBgcqhkjOPQIBBgUr
|
|
10
|
+
gQQAIwOBhgAEAVdXsX8tpA9NAQeEQalvUIcVaFNDvGsR69ysZxOraRWNGHLfq1mi
|
|
11
|
+
P6o3wtmtx/C2OXG01Cw7UFJbKl5MEDxnT2KoAdFSynSJOF2NDoe5LoZHbUW+yR3X
|
|
12
|
+
FDl+MF6JzZ590VLGo6dPBf06UsXbH7PvHH2XKtFt8bBXVNMa5a21RdmpD0Pho0Uw
|
|
13
|
+
QzAOBgNVHQ8BAf8EBAMCAQYwEgYDVR0TAQH/BAgwBgEB/wIBAjAdBgNVHQ4EFgQU
|
|
14
|
+
YBcQng1AEMMNteuRDAMG0/vgFe0wCgYIKoZIzj0EAwQDgYwAMIGIAkIBQU5OTA2h
|
|
15
|
+
YqmFk8paan5ezHVLcmcucsfYw4L/wmeEjCkczRmCVNm6L86LjhWU0v0wER0e+lHO
|
|
16
|
+
3efvjbsu8gIGSagCQgEBnyYMP9gwg8l96QnQ1khFA1ljFlnqc2XgJHDSaAJC0gdz
|
|
17
|
+
+NV3JMeWaD2Rb32jc9r6/a7xY0u0ByqxBQ1OQ0dt7A==
|
|
18
|
+
-----END CERTIFICATE-----
|
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
## ⛅️ wrangler
|
|
2
2
|
|
|
3
|
+
> This package is for wrangler v2.x, released first in May 2022. If you're looking for v1.x of the `@cloudflare/wrangler` package, visit https://www.npmjs.com/package/@cloudflare/wrangler / https://github.com/cloudflare/wrangler.
|
|
4
|
+
|
|
3
5
|
`wrangler` is a command line tool for building [Cloudflare Workers](https://workers.cloudflare.com/).
|
|
4
6
|
|
|
5
7
|
## Quick Start
|
|
@@ -22,7 +24,7 @@ npx wrangler init my-worker
|
|
|
22
24
|
# try it out
|
|
23
25
|
cd my-worker && npm run start
|
|
24
26
|
# and then publish it
|
|
25
|
-
|
|
27
|
+
npm run deploy
|
|
26
28
|
```
|
|
27
29
|
|
|
28
30
|
## Installation:
|
package/bin/wrangler.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const { spawn } = require("
|
|
3
|
-
const
|
|
2
|
+
const { spawn } = require("child_process");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
const fs = require("fs");
|
|
5
|
+
const os = require("os");
|
|
4
6
|
const semiver = require("semiver");
|
|
5
7
|
|
|
6
8
|
const MIN_NODE_VERSION = "16.7.0";
|
|
@@ -20,6 +22,30 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
|
|
|
20
22
|
return;
|
|
21
23
|
}
|
|
22
24
|
|
|
25
|
+
let pathToCACerts = process.env.NODE_EXTRA_CA_CERTS;
|
|
26
|
+
if (pathToCACerts) {
|
|
27
|
+
// TODO:
|
|
28
|
+
// - should we log a warning here?
|
|
29
|
+
// - maybe we can generate a certificate that concatenates with ours?
|
|
30
|
+
//
|
|
31
|
+
// I do think it'll be rare that someone wants to add a cert AND
|
|
32
|
+
// use cloudflare WARP, but let's wait till the situation actually
|
|
33
|
+
// arises before we do anything about it
|
|
34
|
+
} else {
|
|
35
|
+
const osTempDir = os.tmpdir();
|
|
36
|
+
const certDir = path.join(osTempDir, "wrangler-cert");
|
|
37
|
+
const certPath = path.join(certDir, "Cloudflare_CA.pem");
|
|
38
|
+
// copy cert to the system temp dir if needed
|
|
39
|
+
if (!fs.existsSync(certPath)) {
|
|
40
|
+
fs.mkdirSync(certDir, { recursive: true });
|
|
41
|
+
fs.writeFileSync(
|
|
42
|
+
certPath,
|
|
43
|
+
fs.readFileSync(path.join(__dirname, "../Cloudflare_CA.pem"), "utf-8")
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
pathToCACerts = certPath;
|
|
47
|
+
}
|
|
48
|
+
|
|
23
49
|
wranglerProcess = spawn(
|
|
24
50
|
process.execPath,
|
|
25
51
|
[
|
|
@@ -29,10 +55,16 @@ Consider using a Node.js version manager such as https://volta.sh/ or https://gi
|
|
|
29
55
|
"--no-warnings",
|
|
30
56
|
"--experimental-vm-modules",
|
|
31
57
|
...process.execArgv,
|
|
32
|
-
join(__dirname, "../wrangler-dist/cli.js"),
|
|
58
|
+
path.join(__dirname, "../wrangler-dist/cli.js"),
|
|
33
59
|
...process.argv.slice(2),
|
|
34
60
|
],
|
|
35
|
-
{
|
|
61
|
+
{
|
|
62
|
+
stdio: "inherit",
|
|
63
|
+
env: {
|
|
64
|
+
...process.env,
|
|
65
|
+
NODE_EXTRA_CA_CERTS: pathToCACerts,
|
|
66
|
+
},
|
|
67
|
+
}
|
|
36
68
|
).on("exit", (code) =>
|
|
37
69
|
process.exit(code === undefined || code === null ? 0 : code)
|
|
38
70
|
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@cloudflare/kv-asset-handler";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wrangler",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-e322475",
|
|
4
4
|
"author": "wrangler@cloudflare.com",
|
|
5
5
|
"description": "Command-line interface for all things Cloudflare Workers",
|
|
6
6
|
"bin": {
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
},
|
|
10
10
|
"license": "MIT OR Apache-2.0",
|
|
11
11
|
"bugs": {
|
|
12
|
-
"url": "https://github.com/cloudflare/
|
|
12
|
+
"url": "https://github.com/cloudflare/wrangler2/issues"
|
|
13
13
|
},
|
|
14
|
-
"homepage": "https://github.com/cloudflare/
|
|
14
|
+
"homepage": "https://github.com/cloudflare/wrangler2#readme",
|
|
15
15
|
"keywords": [
|
|
16
16
|
"wrangler",
|
|
17
17
|
"cloudflare",
|
|
@@ -36,11 +36,12 @@
|
|
|
36
36
|
"cli"
|
|
37
37
|
],
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"@cloudflare/kv-asset-handler": "^0.2.0",
|
|
39
40
|
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
|
|
40
41
|
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
|
|
41
42
|
"blake3-wasm": "^2.1.5",
|
|
42
43
|
"esbuild": "0.14.34",
|
|
43
|
-
"miniflare": "2.
|
|
44
|
+
"miniflare": "^2.5.1",
|
|
44
45
|
"nanoid": "^3.3.3",
|
|
45
46
|
"path-to-regexp": "^6.2.0",
|
|
46
47
|
"selfsigned": "^2.0.1",
|
|
@@ -62,10 +63,12 @@
|
|
|
62
63
|
"@types/supports-color": "^8.1.1",
|
|
63
64
|
"@types/ws": "^8.5.3",
|
|
64
65
|
"@types/yargs": "^17.0.10",
|
|
66
|
+
"@webcontainer/env": "^1.0.1",
|
|
65
67
|
"chokidar": "^3.5.3",
|
|
66
68
|
"clipboardy": "^3.0.0",
|
|
67
69
|
"cmd-shim": "^4.1.0",
|
|
68
70
|
"command-exists": "^1.2.9",
|
|
71
|
+
"concurrently": "^7.2.2",
|
|
69
72
|
"devtools-protocol": "^0.0.955664",
|
|
70
73
|
"dotenv": "^16.0.0",
|
|
71
74
|
"execa": "^6.1.0",
|
|
@@ -74,6 +77,7 @@
|
|
|
74
77
|
"find-up": "^6.3.0",
|
|
75
78
|
"get-port": "^6.1.2",
|
|
76
79
|
"glob-to-regexp": "0.4.1",
|
|
80
|
+
"http-terminator": "^3.2.0",
|
|
77
81
|
"ignore": "^5.2.0",
|
|
78
82
|
"ink": "^3.2.0",
|
|
79
83
|
"ink-select-input": "^4.2.1",
|
|
@@ -85,6 +89,7 @@
|
|
|
85
89
|
"jest-websocket-mock": "^2.3.0",
|
|
86
90
|
"mime": "^3.0.0",
|
|
87
91
|
"open": "^8.4.0",
|
|
92
|
+
"p-queue": "^7.2.0",
|
|
88
93
|
"pretty-bytes": "^6.0.0",
|
|
89
94
|
"prompts": "^2.4.2",
|
|
90
95
|
"react": "^17.0.2",
|
|
@@ -95,7 +100,7 @@
|
|
|
95
100
|
"timeago.js": "^4.0.2",
|
|
96
101
|
"tmp-promise": "^3.0.3",
|
|
97
102
|
"ts-dedent": "^2.2.0",
|
|
98
|
-
"undici": "^
|
|
103
|
+
"undici": "^5.5.1",
|
|
99
104
|
"update-check": "^1.5.4",
|
|
100
105
|
"ws": "^8.5.0",
|
|
101
106
|
"yargs": "^17.4.1"
|
|
@@ -109,13 +114,16 @@
|
|
|
109
114
|
"wrangler-dist",
|
|
110
115
|
"templates",
|
|
111
116
|
"vendor",
|
|
112
|
-
"import_meta_url.js"
|
|
117
|
+
"import_meta_url.js",
|
|
118
|
+
"kv-asset-handler.js",
|
|
119
|
+
"Cloudflare_CA.pem"
|
|
113
120
|
],
|
|
114
121
|
"scripts": {
|
|
115
122
|
"clean": "rm -rf wrangler-dist miniflare-dist",
|
|
116
123
|
"check:type": "tsc",
|
|
117
124
|
"bundle": "node -r esbuild-register scripts/bundle.ts",
|
|
118
125
|
"build": "npm run clean && npm run bundle",
|
|
126
|
+
"dev": "npm run clean && concurrently -c black,blue 'npm run bundle -- --watch' 'npm run check:type -- --watch --preserveWatchOutput'",
|
|
119
127
|
"prepublishOnly": "SOURCEMAPS=false npm run build",
|
|
120
128
|
"start": "npm run bundle && NODE_OPTIONS=--enable-source-maps ./bin/wrangler.js",
|
|
121
129
|
"test": "jest --silent=false --verbose=true",
|
|
@@ -129,7 +137,7 @@
|
|
|
129
137
|
"testTimeout": 30000,
|
|
130
138
|
"testRegex": ".*.(test|spec)\\.[jt]sx?$",
|
|
131
139
|
"transformIgnorePatterns": [
|
|
132
|
-
"node_modules/(?!find-up|locate-path|p-locate|p-limit|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)"
|
|
140
|
+
"node_modules/(?!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)"
|
|
133
141
|
],
|
|
134
142
|
"moduleNameMapper": {
|
|
135
143
|
"clipboardy": "<rootDir>/src/__tests__/helpers/clipboardy-mock.js",
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { access, lstat } from "node:fs/promises";
|
|
2
2
|
import { dirname, relative, resolve } from "node:path";
|
|
3
|
+
import NodeGlobalsPolyfills from "@esbuild-plugins/node-globals-polyfill";
|
|
4
|
+
import NodeModulesPolyfills from "@esbuild-plugins/node-modules-polyfill";
|
|
3
5
|
import { build } from "esbuild";
|
|
4
6
|
|
|
5
7
|
type Options = {
|
|
@@ -8,6 +10,7 @@ type Options = {
|
|
|
8
10
|
minify?: boolean;
|
|
9
11
|
sourcemap?: boolean;
|
|
10
12
|
watch?: boolean;
|
|
13
|
+
nodeCompat?: boolean;
|
|
11
14
|
onEnd?: () => void;
|
|
12
15
|
};
|
|
13
16
|
|
|
@@ -17,6 +20,7 @@ export function buildPlugin({
|
|
|
17
20
|
minify = false,
|
|
18
21
|
sourcemap = false,
|
|
19
22
|
watch = false,
|
|
23
|
+
nodeCompat,
|
|
20
24
|
onEnd = () => {},
|
|
21
25
|
}: Options) {
|
|
22
26
|
return build({
|
|
@@ -30,6 +34,7 @@ export function buildPlugin({
|
|
|
30
34
|
sourcemap,
|
|
31
35
|
watch,
|
|
32
36
|
allowOverwrite: true,
|
|
37
|
+
define: { ...(nodeCompat ? { global: "globalThis" } : {}) },
|
|
33
38
|
plugins: [
|
|
34
39
|
{
|
|
35
40
|
name: "wrangler notifier and monitor",
|
|
@@ -87,6 +92,14 @@ export function buildPlugin({
|
|
|
87
92
|
}
|
|
88
93
|
},
|
|
89
94
|
},
|
|
95
|
+
...(nodeCompat
|
|
96
|
+
? [
|
|
97
|
+
NodeGlobalsPolyfills({
|
|
98
|
+
buffer: true,
|
|
99
|
+
}),
|
|
100
|
+
NodeModulesPolyfills(),
|
|
101
|
+
]
|
|
102
|
+
: []),
|
|
90
103
|
],
|
|
91
104
|
});
|
|
92
105
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { access, cp, lstat, rm } from "node:fs/promises";
|
|
2
2
|
import { join, resolve } from "node:path";
|
|
3
|
+
import NodeGlobalsPolyfills from "@esbuild-plugins/node-globals-polyfill";
|
|
4
|
+
import NodeModulesPolyfills from "@esbuild-plugins/node-modules-polyfill";
|
|
3
5
|
import { build } from "esbuild";
|
|
4
6
|
import { nanoid } from "nanoid";
|
|
5
7
|
|
|
@@ -12,6 +14,7 @@ type Options = {
|
|
|
12
14
|
watch?: boolean;
|
|
13
15
|
onEnd?: () => void;
|
|
14
16
|
buildOutputDirectory?: string;
|
|
17
|
+
nodeCompat?: boolean;
|
|
15
18
|
};
|
|
16
19
|
|
|
17
20
|
export function buildWorker({
|
|
@@ -23,6 +26,7 @@ export function buildWorker({
|
|
|
23
26
|
watch = false,
|
|
24
27
|
onEnd = () => {},
|
|
25
28
|
buildOutputDirectory,
|
|
29
|
+
nodeCompat,
|
|
26
30
|
}: Options) {
|
|
27
31
|
return build({
|
|
28
32
|
entryPoints: [resolve(__dirname, "../pages/functions/template-worker.ts")],
|
|
@@ -37,6 +41,7 @@ export function buildWorker({
|
|
|
37
41
|
allowOverwrite: true,
|
|
38
42
|
define: {
|
|
39
43
|
__FALLBACK_SERVICE__: JSON.stringify(fallbackService),
|
|
44
|
+
...(nodeCompat ? { global: "globalThis" } : {}),
|
|
40
45
|
},
|
|
41
46
|
plugins: [
|
|
42
47
|
{
|
|
@@ -122,7 +127,7 @@ export function buildWorker({
|
|
|
122
127
|
// TODO: Watch args.path for changes and re-copy when updated
|
|
123
128
|
contents: `export const onRequest = ({ request, env, functionPath }) => {
|
|
124
129
|
const url = new URL(request.url)
|
|
125
|
-
const relativePathname = url.pathname.split(functionPath)[1] ||
|
|
130
|
+
const relativePathname = \`/\${url.pathname.split(functionPath)[1] || ''}\`.replace(/^\\/\\//, '/');
|
|
126
131
|
url.pathname = '/cdn-cgi/pages-plugins/${identifier}' + relativePathname
|
|
127
132
|
request = new Request(url.toString(), request)
|
|
128
133
|
return env.ASSETS.fetch(request)
|
|
@@ -133,6 +138,14 @@ export function buildWorker({
|
|
|
133
138
|
);
|
|
134
139
|
},
|
|
135
140
|
},
|
|
141
|
+
...(nodeCompat
|
|
142
|
+
? [
|
|
143
|
+
NodeGlobalsPolyfills({
|
|
144
|
+
buffer: true,
|
|
145
|
+
}),
|
|
146
|
+
NodeModulesPolyfills(),
|
|
147
|
+
]
|
|
148
|
+
: []),
|
|
136
149
|
],
|
|
137
150
|
});
|
|
138
151
|
}
|
|
@@ -103,8 +103,9 @@ export default function (pluginArgs) {
|
|
|
103
103
|
const { env, next, data } = workerContext;
|
|
104
104
|
|
|
105
105
|
const url = new URL(request.url);
|
|
106
|
-
const relativePathname =
|
|
107
|
-
url.pathname.split(workerContext.functionPath)[1] || "
|
|
106
|
+
const relativePathname = `/${
|
|
107
|
+
url.pathname.split(workerContext.functionPath)[1] || ""
|
|
108
|
+
}`.replace(/^\/\//, "/");
|
|
108
109
|
|
|
109
110
|
const handlerIterator = executeRequest(request, relativePathname);
|
|
110
111
|
const pluginNext = async (input?: RequestInfo, init?: RequestInit) => {
|