wrangler 0.0.0-e1c615f → 0.0.0-e3cab74
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/bin/wrangler.js +2 -2
- package/package.json +28 -13
- package/pages/functions/buildWorker.ts +6 -1
- package/pages/functions/filepath-routing.test.ts +112 -28
- package/pages/functions/filepath-routing.ts +88 -131
- package/pages/functions/routes.ts +11 -18
- package/pages/functions/template-worker.ts +21 -28
- package/src/__tests__/configuration.test.ts +2185 -0
- package/src/__tests__/dev.test.tsx +56 -9
- package/src/__tests__/guess-worker-format.test.ts +66 -0
- package/src/__tests__/{clipboardy-mock.js → helpers/clipboardy-mock.js} +0 -0
- package/src/__tests__/helpers/cmd-shim.d.ts +11 -0
- package/src/__tests__/helpers/faye-websocket.d.ts +6 -0
- package/src/__tests__/helpers/mock-account-id.ts +30 -0
- package/src/__tests__/helpers/mock-bin.ts +36 -0
- package/src/__tests__/{mock-cfetch.ts → helpers/mock-cfetch.ts} +53 -17
- package/src/__tests__/helpers/mock-console.ts +62 -0
- package/src/__tests__/{mock-dialogs.ts → helpers/mock-dialogs.ts} +1 -1
- package/src/__tests__/helpers/mock-kv.ts +40 -0
- package/src/__tests__/helpers/mock-user.ts +27 -0
- package/src/__tests__/helpers/mock-web-socket.ts +29 -0
- package/src/__tests__/helpers/run-in-tmp.ts +29 -0
- package/src/__tests__/helpers/run-wrangler.ts +16 -0
- package/src/__tests__/helpers/write-wrangler-toml.ts +17 -0
- package/src/__tests__/index.test.ts +655 -76
- package/src/__tests__/jest.setup.ts +37 -2
- package/src/__tests__/kv.test.ts +441 -398
- package/src/__tests__/logout.test.ts +50 -0
- package/src/__tests__/package-manager.test.ts +206 -0
- package/src/__tests__/parse.test.ts +322 -0
- package/src/__tests__/publish.test.ts +2406 -0
- package/src/__tests__/r2.test.ts +198 -0
- package/src/__tests__/secret.test.ts +326 -0
- package/src/__tests__/sentry.test.ts +146 -0
- package/src/__tests__/tail.test.ts +564 -0
- package/src/__tests__/whoami.test.tsx +86 -0
- package/src/api/form_data.ts +112 -26
- package/src/api/preview.ts +34 -15
- package/src/api/worker.ts +58 -27
- package/src/bundle.ts +133 -0
- package/src/cfetch/index.ts +21 -19
- package/src/cfetch/internal.ts +85 -21
- package/src/cli.ts +10 -0
- package/src/config/README.md +107 -0
- package/src/config/config.ts +265 -0
- package/src/config/diagnostics.ts +80 -0
- package/src/config/environment.ts +305 -0
- package/src/config/index.ts +52 -0
- package/src/config/validation-helpers.ts +370 -0
- package/src/config/validation.ts +1017 -0
- package/src/dev.tsx +455 -368
- package/src/dialogs.tsx +2 -2
- package/src/entry.ts +57 -0
- package/src/environment-variables.ts +33 -0
- package/src/guess-worker-format.ts +68 -0
- package/src/index.tsx +1044 -646
- package/src/inspect.ts +609 -0
- package/src/kv.tsx +47 -39
- package/src/module-collection.ts +142 -36
- package/src/open-in-browser.ts +13 -0
- package/src/package-manager.ts +126 -0
- package/src/pages.tsx +139 -62
- package/src/parse.ts +183 -0
- package/src/paths.ts +26 -0
- package/src/proxy.ts +350 -77
- package/src/publish.ts +307 -289
- package/src/r2.ts +50 -0
- package/src/reporting.ts +115 -0
- package/src/sites.tsx +183 -56
- package/src/tail/filters.ts +279 -0
- package/src/tail/index.ts +299 -0
- package/src/tail/printing.ts +62 -0
- package/src/user.tsx +137 -110
- package/src/whoami.tsx +69 -0
- package/templates/new-worker.js +15 -0
- package/templates/new-worker.ts +15 -0
- package/{static-asset-facade.js → templates/static-asset-facade.js} +0 -0
- package/templates/tsconfig.json +105 -0
- package/wrangler-dist/cli.js +127861 -111486
- package/wrangler-dist/cli.js.map +3 -3
- package/src/__tests__/run-in-tmp.ts +0 -19
- package/src/__tests__/run-wrangler.ts +0 -32
- package/src/api/inspect.ts +0 -430
- package/src/config.ts +0 -131
- package/src/tail.tsx +0 -73
|
@@ -22,33 +22,32 @@ declare type PagesFunction<
|
|
|
22
22
|
|
|
23
23
|
type RouteHandler = {
|
|
24
24
|
routePath: string;
|
|
25
|
-
|
|
25
|
+
method?: HTTPMethod;
|
|
26
26
|
modules: PagesFunction[];
|
|
27
27
|
middlewares: PagesFunction[];
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
// inject `routes` via ESBuild
|
|
31
31
|
declare const routes: RouteHandler[];
|
|
32
|
+
// define `__FALLBACK_SERVICE__` via ESBuild
|
|
33
|
+
declare const __FALLBACK_SERVICE__: string;
|
|
32
34
|
|
|
33
35
|
// expect an ASSETS fetcher binding pointing to the asset-server stage
|
|
34
|
-
type
|
|
35
|
-
[name: string]:
|
|
36
|
-
ASSETS: { fetch
|
|
36
|
+
type FetchEnv = {
|
|
37
|
+
[name: string]: { fetch: typeof fetch };
|
|
38
|
+
ASSETS: { fetch: typeof fetch };
|
|
37
39
|
};
|
|
38
40
|
|
|
39
41
|
type WorkerContext = {
|
|
40
42
|
waitUntil: (promise: Promise<unknown>) => void;
|
|
41
43
|
};
|
|
42
44
|
|
|
43
|
-
function* executeRequest(request: Request,
|
|
45
|
+
function* executeRequest(request: Request, _env: FetchEnv) {
|
|
44
46
|
const requestPath = new URL(request.url).pathname;
|
|
45
47
|
|
|
46
48
|
// First, iterate through the routes (backwards) and execute "middlewares" on partial route matches
|
|
47
49
|
for (const route of [...routes].reverse()) {
|
|
48
|
-
if (
|
|
49
|
-
route.methods.length &&
|
|
50
|
-
!route.methods.includes(request.method as HTTPMethod)
|
|
51
|
-
) {
|
|
50
|
+
if (route.method && route.method !== request.method) {
|
|
52
51
|
continue;
|
|
53
52
|
}
|
|
54
53
|
|
|
@@ -66,10 +65,7 @@ function* executeRequest(request: Request, env: Env) {
|
|
|
66
65
|
|
|
67
66
|
// Then look for the first exact route match and execute its "modules"
|
|
68
67
|
for (const route of routes) {
|
|
69
|
-
if (
|
|
70
|
-
route.methods.length &&
|
|
71
|
-
!route.methods.includes(request.method as HTTPMethod)
|
|
72
|
-
) {
|
|
68
|
+
if (route.method && route.method !== request.method) {
|
|
73
69
|
continue;
|
|
74
70
|
}
|
|
75
71
|
|
|
@@ -85,16 +81,10 @@ function* executeRequest(request: Request, env: Env) {
|
|
|
85
81
|
break;
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
|
-
|
|
89
|
-
// Finally, yield to the asset-server
|
|
90
|
-
return {
|
|
91
|
-
handler: () => env.ASSETS.fetch(request.url, request),
|
|
92
|
-
params: {} as Params,
|
|
93
|
-
};
|
|
94
84
|
}
|
|
95
85
|
|
|
96
86
|
export default {
|
|
97
|
-
async fetch(request: Request, env:
|
|
87
|
+
async fetch(request: Request, env: FetchEnv, workerContext: WorkerContext) {
|
|
98
88
|
const handlerIterator = executeRequest(request, env);
|
|
99
89
|
const data = {}; // arbitrary data the user can set between functions
|
|
100
90
|
const next = async (input?: RequestInfo, init?: RequestInit) => {
|
|
@@ -102,14 +92,11 @@ export default {
|
|
|
102
92
|
request = new Request(input, init);
|
|
103
93
|
}
|
|
104
94
|
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const
|
|
109
|
-
|
|
110
|
-
string,
|
|
111
|
-
Record<string, unknown>
|
|
112
|
-
> = {
|
|
95
|
+
const result = handlerIterator.next();
|
|
96
|
+
// Note we can't use `!result.done` because this doesn't narrow to the correct type
|
|
97
|
+
if (result.done == false) {
|
|
98
|
+
const { handler, params } = result.value;
|
|
99
|
+
const context = {
|
|
113
100
|
request: new Request(request.clone()),
|
|
114
101
|
next,
|
|
115
102
|
params,
|
|
@@ -125,6 +112,12 @@ export default {
|
|
|
125
112
|
[101, 204, 205, 304].includes(response.status) ? null : response.body,
|
|
126
113
|
response
|
|
127
114
|
);
|
|
115
|
+
} else if (__FALLBACK_SERVICE__) {
|
|
116
|
+
// There are no more handlers so finish with the fallback service (`env.ASSETS.fetch` in Pages' case)
|
|
117
|
+
return env[__FALLBACK_SERVICE__].fetch(request);
|
|
118
|
+
} else {
|
|
119
|
+
// There was not fallback service so actually make the request to the origin.
|
|
120
|
+
return fetch(request);
|
|
128
121
|
}
|
|
129
122
|
};
|
|
130
123
|
|