wrangler 0.0.0-e7a0cd5b → 0.0.0-e7c06d78
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 +13 -15
- package/bin/wrangler.js +24 -93
- package/config-schema.json +3059 -0
- package/package.json +196 -191
- package/templates/__tests__/tsconfig-sanity.ts +12 -0
- package/templates/__tests__/tsconfig.json +8 -0
- package/templates/checked-fetch.js +19 -6
- package/templates/facade.d.ts +19 -0
- package/templates/gitignore +2 -3
- package/templates/init-tests/test-jest-new-worker.js +3 -5
- package/templates/init-tests/test-vitest-new-worker.js +4 -6
- package/templates/init-tests/test-vitest-new-worker.ts +25 -0
- package/templates/middleware/common.ts +9 -4
- package/templates/middleware/loader-modules.ts +94 -44
- package/templates/middleware/loader-sw.ts +48 -32
- package/templates/middleware/middleware-ensure-req-body-drained.ts +18 -0
- package/templates/middleware/middleware-miniflare3-json-error.ts +32 -0
- package/templates/middleware/middleware-serve-static-assets.d.ts +6 -0
- package/templates/middleware/middleware-serve-static-assets.ts +56 -0
- package/templates/modules-watch-stub.js +4 -0
- package/templates/new-worker-scheduled.ts +1 -1
- package/templates/new-worker.ts +4 -1
- package/templates/pages-dev-pipeline.ts +6 -2
- package/templates/pages-dev-util.ts +4 -1
- package/templates/pages-shim.ts +1 -1
- package/templates/pages-template-plugin.ts +33 -14
- package/templates/pages-template-worker.ts +12 -3
- package/templates/startDevWorker/InspectorProxyWorker.ts +664 -0
- package/templates/startDevWorker/ProxyWorker.ts +334 -0
- package/templates/tsconfig-sanity.ts +11 -0
- package/templates/tsconfig.init.json +22 -0
- package/templates/tsconfig.json +5 -103
- package/wrangler-dist/InspectorProxyWorker.js +464 -0
- package/wrangler-dist/InspectorProxyWorker.js.map +6 -0
- package/wrangler-dist/ProxyWorker.js +240 -0
- package/wrangler-dist/ProxyWorker.js.map +6 -0
- package/wrangler-dist/cli.d.ts +26010 -512
- package/wrangler-dist/cli.js +164971 -116798
- package/wrangler-dist/wasm-sync.wasm +0 -0
- package/Cloudflare_CA.pem +0 -18
- package/import_meta_url.js +0 -3
- package/miniflare-config-stubs/.env.empty +0 -0
- package/miniflare-config-stubs/package.empty.json +0 -1
- package/miniflare-config-stubs/wrangler.empty.toml +0 -0
- package/miniflare-dist/index.mjs +0 -6316
- package/src/__tests__/access.test.ts +0 -25
- package/src/__tests__/api-dev.test.ts +0 -209
- package/src/__tests__/api-devregistry.test.js +0 -57
- package/src/__tests__/api.test.ts +0 -80
- package/src/__tests__/config-cache-without-cache-dir.test.ts +0 -38
- package/src/__tests__/config-cache.test.ts +0 -42
- package/src/__tests__/configuration.test.ts +0 -4028
- package/src/__tests__/d1.test.ts +0 -72
- package/src/__tests__/delete.test.ts +0 -230
- package/src/__tests__/deployments.test.ts +0 -95
- package/src/__tests__/dev.test.tsx +0 -1509
- package/src/__tests__/dialogs.test.tsx +0 -40
- package/src/__tests__/generate.test.ts +0 -235
- package/src/__tests__/get-host-from-url.test.ts +0 -16
- package/src/__tests__/guess-worker-format.test.ts +0 -85
- package/src/__tests__/helpers/clipboardy-mock.js +0 -4
- package/src/__tests__/helpers/cmd-shim.d.ts +0 -11
- package/src/__tests__/helpers/mock-account-id.ts +0 -48
- package/src/__tests__/helpers/mock-bin.ts +0 -36
- package/src/__tests__/helpers/mock-cfetch.ts +0 -333
- package/src/__tests__/helpers/mock-console.ts +0 -106
- package/src/__tests__/helpers/mock-dialogs.ts +0 -153
- package/src/__tests__/helpers/mock-get-zone-from-host.ts +0 -8
- package/src/__tests__/helpers/mock-http-server.ts +0 -46
- package/src/__tests__/helpers/mock-istty.ts +0 -74
- package/src/__tests__/helpers/mock-known-routes.ts +0 -7
- package/src/__tests__/helpers/mock-kv.ts +0 -33
- package/src/__tests__/helpers/mock-oauth-flow.ts +0 -252
- package/src/__tests__/helpers/mock-process.ts +0 -39
- package/src/__tests__/helpers/mock-stdin.ts +0 -108
- package/src/__tests__/helpers/mock-web-socket.ts +0 -29
- package/src/__tests__/helpers/msw/handlers/access.ts +0 -13
- package/src/__tests__/helpers/msw/handlers/deployments.ts +0 -59
- package/src/__tests__/helpers/msw/handlers/namespaces.ts +0 -104
- package/src/__tests__/helpers/msw/handlers/oauth.ts +0 -36
- package/src/__tests__/helpers/msw/handlers/r2.ts +0 -80
- package/src/__tests__/helpers/msw/handlers/script.ts +0 -75
- package/src/__tests__/helpers/msw/handlers/user.ts +0 -63
- package/src/__tests__/helpers/msw/handlers/zones.ts +0 -22
- package/src/__tests__/helpers/msw/index.ts +0 -21
- package/src/__tests__/helpers/run-in-tmp.ts +0 -38
- package/src/__tests__/helpers/run-wrangler.ts +0 -16
- package/src/__tests__/helpers/worker-scripts/child-wrangler.toml +0 -1
- package/src/__tests__/helpers/worker-scripts/hello-world-worker.js +0 -5
- package/src/__tests__/helpers/worker-scripts/hello-world-wrangler.toml +0 -1
- package/src/__tests__/helpers/worker-scripts/parent-worker.js +0 -8
- package/src/__tests__/helpers/worker-scripts/parent-wrangler.toml +0 -5
- package/src/__tests__/helpers/write-worker-source.ts +0 -31
- package/src/__tests__/helpers/write-wrangler-toml.ts +0 -17
- package/src/__tests__/https-options.test.ts +0 -163
- package/src/__tests__/index.test.ts +0 -262
- package/src/__tests__/init.test.ts +0 -2900
- package/src/__tests__/jest.setup.ts +0 -202
- package/src/__tests__/kv.test.ts +0 -1675
- package/src/__tests__/logger.test.ts +0 -141
- package/src/__tests__/metrics.test.ts +0 -450
- package/src/__tests__/middleware.scheduled.test.ts +0 -135
- package/src/__tests__/middleware.test.ts +0 -726
- package/src/__tests__/package-manager.test.ts +0 -353
- package/src/__tests__/pages.test.ts +0 -2223
- package/src/__tests__/parse.test.ts +0 -330
- package/src/__tests__/paths.test.ts +0 -39
- package/src/__tests__/publish.test.ts +0 -7660
- package/src/__tests__/pubsub.test.ts +0 -370
- package/src/__tests__/queues.test.ts +0 -371
- package/src/__tests__/r2.test.ts +0 -376
- package/src/__tests__/route.test.ts +0 -45
- package/src/__tests__/secret.test.ts +0 -644
- package/src/__tests__/tail.test.ts +0 -800
- package/src/__tests__/test-old-node-version.js +0 -31
- package/src/__tests__/type-generation.test.ts +0 -217
- package/src/__tests__/user.test.ts +0 -155
- package/src/__tests__/utils-collectKeyValues.test.ts +0 -47
- package/src/__tests__/validate-dev-props.test.ts +0 -56
- package/src/__tests__/version.test.ts +0 -35
- package/src/__tests__/whoami.test.tsx +0 -278
- package/src/__tests__/worker-namespace.test.ts +0 -326
- package/src/abort.d.ts +0 -3
- package/src/api/dev.ts +0 -208
- package/src/api/index.ts +0 -2
- package/src/bundle-reporter.tsx +0 -68
- package/src/bundle.ts +0 -785
- package/src/cfetch/index.ts +0 -160
- package/src/cfetch/internal.ts +0 -263
- package/src/cli.ts +0 -28
- package/src/config/README.md +0 -107
- package/src/config/config.ts +0 -275
- package/src/config/diagnostics.ts +0 -80
- package/src/config/environment.ts +0 -563
- package/src/config/index.ts +0 -342
- package/src/config/validation-helpers.ts +0 -597
- package/src/config/validation.ts +0 -2113
- package/src/config-cache.ts +0 -85
- package/src/create-worker-preview.ts +0 -282
- package/src/create-worker-upload-form.ts +0 -321
- package/src/d1/backups.tsx +0 -218
- package/src/d1/create.tsx +0 -54
- package/src/d1/delete.tsx +0 -56
- package/src/d1/execute.tsx +0 -299
- package/src/d1/formatTimeAgo.ts +0 -14
- package/src/d1/index.ts +0 -76
- package/src/d1/list.tsx +0 -48
- package/src/d1/options.ts +0 -12
- package/src/d1/types.tsx +0 -14
- package/src/d1/utils.ts +0 -39
- package/src/delete.ts +0 -108
- package/src/deployments.ts +0 -74
- package/src/deprecated/index.ts +0 -438
- package/src/dev/dev-vars.ts +0 -39
- package/src/dev/dev.tsx +0 -587
- package/src/dev/get-local-persistence-path.tsx +0 -31
- package/src/dev/local.tsx +0 -717
- package/src/dev/remote.tsx +0 -603
- package/src/dev/start-server.ts +0 -513
- package/src/dev/use-esbuild.ts +0 -204
- package/src/dev/validate-dev-props.ts +0 -31
- package/src/dev-registry.tsx +0 -201
- package/src/dev.tsx +0 -869
- package/src/dialogs.tsx +0 -163
- package/src/dispatch-namespace.ts +0 -207
- package/src/durable.ts +0 -102
- package/src/entry.ts +0 -329
- package/src/environment-variables.ts +0 -50
- package/src/errors.ts +0 -11
- package/src/git-client.ts +0 -124
- package/src/global-wrangler-config-path.ts +0 -26
- package/src/https-options.ts +0 -127
- package/src/index.tsx +0 -684
- package/src/init.ts +0 -970
- package/src/inspect.ts +0 -767
- package/src/intl-polyfill.d.ts +0 -139
- package/src/is-ci.ts +0 -14
- package/src/is-interactive.ts +0 -16
- package/src/kv/helpers.ts +0 -430
- package/src/kv/index.ts +0 -596
- package/src/logger.ts +0 -92
- package/src/metrics/index.ts +0 -5
- package/src/metrics/metrics-config.ts +0 -239
- package/src/metrics/metrics-dispatcher.ts +0 -96
- package/src/metrics/metrics-usage-headers.ts +0 -24
- package/src/metrics/send-event.ts +0 -94
- package/src/miniflare-cli/README.md +0 -30
- package/src/miniflare-cli/assets.ts +0 -215
- package/src/miniflare-cli/index.ts +0 -213
- package/src/miniflare-cli/request-context.ts +0 -40
- package/src/module-collection.ts +0 -267
- package/src/open-in-browser.ts +0 -17
- package/src/package-manager.ts +0 -219
- package/src/pages/build.tsx +0 -238
- package/src/pages/constants.ts +0 -18
- package/src/pages/deployments.tsx +0 -106
- package/src/pages/dev.tsx +0 -693
- package/src/pages/errors.ts +0 -66
- package/src/pages/functions/buildPlugin.ts +0 -110
- package/src/pages/functions/buildWorker.ts +0 -156
- package/src/pages/functions/filepath-routing.test.ts +0 -234
- package/src/pages/functions/filepath-routing.ts +0 -189
- package/src/pages/functions/identifiers.ts +0 -78
- package/src/pages/functions/routes-consolidation.test.ts +0 -250
- package/src/pages/functions/routes-consolidation.ts +0 -73
- package/src/pages/functions/routes-transformation.test.ts +0 -282
- package/src/pages/functions/routes-transformation.ts +0 -115
- package/src/pages/functions/routes-validation.test.ts +0 -403
- package/src/pages/functions/routes-validation.ts +0 -202
- package/src/pages/functions/routes.ts +0 -151
- package/src/pages/functions.tsx +0 -82
- package/src/pages/hash.tsx +0 -13
- package/src/pages/index.tsx +0 -94
- package/src/pages/projects.tsx +0 -169
- package/src/pages/publish.tsx +0 -436
- package/src/pages/types.ts +0 -49
- package/src/pages/upload.tsx +0 -425
- package/src/pages/utils.ts +0 -12
- package/src/parse.ts +0 -286
- package/src/paths.ts +0 -71
- package/src/proxy.ts +0 -689
- package/src/publish/index.ts +0 -270
- package/src/publish/publish.ts +0 -1035
- package/src/pubsub/index.ts +0 -286
- package/src/pubsub/pubsub-commands.tsx +0 -624
- package/src/queues/cli/commands/consumer/add.ts +0 -71
- package/src/queues/cli/commands/consumer/index.ts +0 -22
- package/src/queues/cli/commands/consumer/remove.ts +0 -38
- package/src/queues/cli/commands/create.ts +0 -25
- package/src/queues/cli/commands/delete.ts +0 -26
- package/src/queues/cli/commands/index.ts +0 -33
- package/src/queues/cli/commands/list.ts +0 -25
- package/src/queues/client.ts +0 -135
- package/src/r2/helpers.ts +0 -131
- package/src/r2/index.ts +0 -277
- package/src/routes.ts +0 -140
- package/src/secret/index.ts +0 -379
- package/src/selfsigned.d.ts +0 -29
- package/src/sites.tsx +0 -372
- package/src/tail/createTail.ts +0 -315
- package/src/tail/filters.ts +0 -277
- package/src/tail/index.ts +0 -214
- package/src/tail/printing.ts +0 -107
- package/src/type-generation.ts +0 -159
- package/src/update-check.ts +0 -19
- package/src/user/access.ts +0 -69
- package/src/user/choose-account.tsx +0 -69
- package/src/user/env-vars.ts +0 -46
- package/src/user/generate-auth-url.ts +0 -33
- package/src/user/generate-random-state.ts +0 -16
- package/src/user/index.ts +0 -3
- package/src/user/user.tsx +0 -1192
- package/src/utils/collectKeyValues.ts +0 -14
- package/src/whoami.tsx +0 -169
- package/src/worker.ts +0 -242
- package/src/yargs-types.ts +0 -20
- package/src/zones.ts +0 -191
- package/templates/d1-beta-facade.js +0 -174
- package/templates/experimental-local-cache-stubs.js +0 -27
- package/templates/first-party-worker-module-facade.ts +0 -18
- package/templates/format-dev-errors.ts +0 -32
- package/templates/serve-static-assets.ts +0 -63
- package/templates/service-bindings-module-facade.js +0 -54
- package/templates/service-bindings-sw-facade.js +0 -42
|
@@ -1,174 +0,0 @@
|
|
|
1
|
-
// src/shim.ts
|
|
2
|
-
import worker from "__ENTRY_POINT__";
|
|
3
|
-
export * from "__ENTRY_POINT__";
|
|
4
|
-
|
|
5
|
-
// src/index.ts
|
|
6
|
-
var D1Database = class {
|
|
7
|
-
constructor(binding) {
|
|
8
|
-
this.binding = binding;
|
|
9
|
-
}
|
|
10
|
-
prepare(query) {
|
|
11
|
-
return new D1PreparedStatement(this, query);
|
|
12
|
-
}
|
|
13
|
-
async dump() {
|
|
14
|
-
const response = await this.binding.fetch("/dump", {
|
|
15
|
-
method: "POST",
|
|
16
|
-
headers: {
|
|
17
|
-
"content-type": "application/json",
|
|
18
|
-
},
|
|
19
|
-
});
|
|
20
|
-
if (response.status !== 200) {
|
|
21
|
-
const err = await response.json();
|
|
22
|
-
throw new Error("D1_DUMP_ERROR", {
|
|
23
|
-
cause: new Error(err.error),
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
return await response.arrayBuffer();
|
|
27
|
-
}
|
|
28
|
-
async batch(statements) {
|
|
29
|
-
const exec = await this._send(
|
|
30
|
-
"/query",
|
|
31
|
-
statements.map((s) => s.statement),
|
|
32
|
-
statements.map((s) => s.params)
|
|
33
|
-
);
|
|
34
|
-
return exec;
|
|
35
|
-
}
|
|
36
|
-
async exec(query) {
|
|
37
|
-
const lines = query.trim().split("\n");
|
|
38
|
-
const _exec = await this._send("/query", lines, []);
|
|
39
|
-
const exec = Array.isArray(_exec) ? _exec : [_exec];
|
|
40
|
-
const error = exec
|
|
41
|
-
.map((r) => {
|
|
42
|
-
return r.error ? 1 : 0;
|
|
43
|
-
})
|
|
44
|
-
.indexOf(1);
|
|
45
|
-
if (error !== -1) {
|
|
46
|
-
throw new Error("D1_EXEC_ERROR", {
|
|
47
|
-
cause: new Error(
|
|
48
|
-
`Error in line ${error + 1}: ${lines[error]}: ${exec[error].error}`
|
|
49
|
-
),
|
|
50
|
-
});
|
|
51
|
-
} else {
|
|
52
|
-
return {
|
|
53
|
-
count: exec.length,
|
|
54
|
-
duration: exec.reduce((p, c) => {
|
|
55
|
-
return p + c.duration;
|
|
56
|
-
}, 0),
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
async _send(endpoint, query, params) {
|
|
61
|
-
const body = JSON.stringify(
|
|
62
|
-
typeof query == "object"
|
|
63
|
-
? query.map((s, index) => {
|
|
64
|
-
return { sql: s, params: params[index] };
|
|
65
|
-
})
|
|
66
|
-
: {
|
|
67
|
-
sql: query,
|
|
68
|
-
params,
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
const response = await this.binding.fetch(endpoint, {
|
|
72
|
-
method: "POST",
|
|
73
|
-
headers: {
|
|
74
|
-
"content-type": "application/json",
|
|
75
|
-
},
|
|
76
|
-
body,
|
|
77
|
-
});
|
|
78
|
-
if (response.status !== 200) {
|
|
79
|
-
const err = await response.json();
|
|
80
|
-
throw new Error("D1_ERROR", { cause: new Error(err.error) });
|
|
81
|
-
}
|
|
82
|
-
const answer = await response.json();
|
|
83
|
-
return Array.isArray(answer) ? answer : answer;
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
var D1PreparedStatement = class {
|
|
87
|
-
constructor(database, statement, values) {
|
|
88
|
-
this.database = database;
|
|
89
|
-
this.statement = statement;
|
|
90
|
-
this.params = values || [];
|
|
91
|
-
}
|
|
92
|
-
bind(...values) {
|
|
93
|
-
return new D1PreparedStatement(this.database, this.statement, values);
|
|
94
|
-
}
|
|
95
|
-
async first(colName) {
|
|
96
|
-
const info = firstIfArray(
|
|
97
|
-
await this.database._send("/query", this.statement, this.params)
|
|
98
|
-
);
|
|
99
|
-
const results = info.results;
|
|
100
|
-
if (results.length < 1) {
|
|
101
|
-
throw new Error("D1_NORESULTS", { cause: new Error("No results") });
|
|
102
|
-
}
|
|
103
|
-
const result = results[0];
|
|
104
|
-
if (colName !== void 0) {
|
|
105
|
-
if (result[colName] === void 0) {
|
|
106
|
-
throw new Error("D1_COLUMN_NOTFOUND", {
|
|
107
|
-
cause: new Error(`Column not found`),
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
return result[colName];
|
|
111
|
-
} else {
|
|
112
|
-
return result;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
async run() {
|
|
116
|
-
return firstIfArray(
|
|
117
|
-
await this.database._send("/execute", this.statement, this.params)
|
|
118
|
-
);
|
|
119
|
-
}
|
|
120
|
-
async all() {
|
|
121
|
-
return firstIfArray(
|
|
122
|
-
await this.database._send("/query", this.statement, this.params)
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
async raw() {
|
|
126
|
-
const s = firstIfArray(
|
|
127
|
-
await this.database._send("/query", this.statement, this.params)
|
|
128
|
-
);
|
|
129
|
-
const raw = [];
|
|
130
|
-
for (var r in s.results) {
|
|
131
|
-
const entry = Object.keys(s.results[r]).map((k) => {
|
|
132
|
-
return s.results[r][k];
|
|
133
|
-
});
|
|
134
|
-
raw.push(entry);
|
|
135
|
-
}
|
|
136
|
-
return raw;
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
function firstIfArray(results) {
|
|
140
|
-
return Array.isArray(results) ? results[0] : results;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// src/shim.ts
|
|
144
|
-
var D1_IMPORTS = __D1_IMPORTS__;
|
|
145
|
-
var LOCAL_MODE = __LOCAL_MODE__;
|
|
146
|
-
var D1_BETA_PREFIX = `__D1_BETA__`;
|
|
147
|
-
var envMap = /* @__PURE__ */ new Map();
|
|
148
|
-
function getMaskedEnv(env) {
|
|
149
|
-
if (envMap.has(env)) return envMap.get(env);
|
|
150
|
-
const newEnv = new Map(Object.entries(env));
|
|
151
|
-
D1_IMPORTS.filter((bindingName) =>
|
|
152
|
-
bindingName.startsWith(D1_BETA_PREFIX)
|
|
153
|
-
).forEach((bindingName) => {
|
|
154
|
-
newEnv.delete(bindingName);
|
|
155
|
-
const newName = bindingName.slice(D1_BETA_PREFIX.length);
|
|
156
|
-
const newBinding = !LOCAL_MODE
|
|
157
|
-
? new D1Database(env[bindingName])
|
|
158
|
-
: env[bindingName];
|
|
159
|
-
newEnv.set(newName, newBinding);
|
|
160
|
-
});
|
|
161
|
-
const newEnvObj = Object.fromEntries(newEnv.entries());
|
|
162
|
-
envMap.set(env, newEnvObj);
|
|
163
|
-
return newEnvObj;
|
|
164
|
-
}
|
|
165
|
-
var shim_default = {
|
|
166
|
-
async fetch(request, env, ctx) {
|
|
167
|
-
return worker.fetch(request, getMaskedEnv(env), ctx);
|
|
168
|
-
},
|
|
169
|
-
|
|
170
|
-
async scheduled(controller, env, ctx) {
|
|
171
|
-
return worker.scheduled(controller, getMaskedEnv(env), ctx);
|
|
172
|
-
},
|
|
173
|
-
};
|
|
174
|
-
export { shim_default as default };
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// `workerd` currently throws on any use of the Cache API. Workers Sites
|
|
2
|
-
// requires the Cache API to function though, so stub it out to no-ops, like in
|
|
3
|
-
// regular `wrangler dev`.
|
|
4
|
-
|
|
5
|
-
class Cache {
|
|
6
|
-
async put(req, res) {}
|
|
7
|
-
|
|
8
|
-
async match(req, options) {}
|
|
9
|
-
|
|
10
|
-
async delete(req, options) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
class CacheStorage {
|
|
16
|
-
#cache = new Cache();
|
|
17
|
-
|
|
18
|
-
get default() {
|
|
19
|
-
return this.#cache;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
async open(cacheName) {
|
|
23
|
-
return this.#cache;
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
globalThis.caches = new CacheStorage();
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
// @ts-ignore entry point will get replaced
|
|
2
|
-
import worker from "__ENTRY_POINT__";
|
|
3
|
-
// @ts-ignore entry point will get replaced
|
|
4
|
-
export * from "__ENTRY_POINT__";
|
|
5
|
-
|
|
6
|
-
type Env = {
|
|
7
|
-
// TODO: type this
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Setup globals/vars as required
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
export default {
|
|
15
|
-
async fetch(request: Request, env: Env, ctx: ExecutionContext) {
|
|
16
|
-
return worker.fetch(request, env, ctx);
|
|
17
|
-
},
|
|
18
|
-
};
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
// @ts-expect-error We'll swap in the entry point during build
|
|
2
|
-
import Worker from "__ENTRY_POINT__";
|
|
3
|
-
|
|
4
|
-
// @ts-expect-error
|
|
5
|
-
export * from "__ENTRY_POINT__";
|
|
6
|
-
|
|
7
|
-
export default {
|
|
8
|
-
async fetch(req: Request, env: unknown, ctx: ExecutionContext) {
|
|
9
|
-
try {
|
|
10
|
-
return await Worker.fetch(req, env, ctx);
|
|
11
|
-
} catch (err) {
|
|
12
|
-
return new Response(
|
|
13
|
-
`<!DOCTYPE html>
|
|
14
|
-
<html>
|
|
15
|
-
<head>
|
|
16
|
-
<meta charset="utf-8" />
|
|
17
|
-
<title>Error</title>
|
|
18
|
-
</head>
|
|
19
|
-
<body>
|
|
20
|
-
<pre>${(err as Error).stack}</pre>
|
|
21
|
-
</body>
|
|
22
|
-
</html>`,
|
|
23
|
-
{
|
|
24
|
-
status: 500,
|
|
25
|
-
headers: {
|
|
26
|
-
"Content-Type": "text/html",
|
|
27
|
-
},
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
};
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
// @ts-expect-error
|
|
2
|
-
import worker from "__ENTRY_POINT__";
|
|
3
|
-
import {
|
|
4
|
-
getAssetFromKV,
|
|
5
|
-
NotFoundError,
|
|
6
|
-
MethodNotAllowedError,
|
|
7
|
-
// @ts-expect-error
|
|
8
|
-
} from "__KV_ASSET_HANDLER__";
|
|
9
|
-
// @ts-expect-error
|
|
10
|
-
import manifest from "__STATIC_CONTENT_MANIFEST";
|
|
11
|
-
import type * as kvAssetHandler from "@cloudflare/kv-asset-handler";
|
|
12
|
-
|
|
13
|
-
const ASSET_MANIFEST = JSON.parse(manifest);
|
|
14
|
-
|
|
15
|
-
// @ts-expect-error
|
|
16
|
-
export * from "__ENTRY_POINT__";
|
|
17
|
-
|
|
18
|
-
export default {
|
|
19
|
-
async fetch(
|
|
20
|
-
request: Request,
|
|
21
|
-
env: { __STATIC_CONTENT: string },
|
|
22
|
-
ctx: ExecutionContext
|
|
23
|
-
) {
|
|
24
|
-
let options = {
|
|
25
|
-
ASSET_MANIFEST,
|
|
26
|
-
ASSET_NAMESPACE: env.__STATIC_CONTENT,
|
|
27
|
-
cacheControl: __CACHE_CONTROL_OPTIONS__,
|
|
28
|
-
serveSinglePageApp: __SERVE_SINGLE_PAGE_APP__,
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
try {
|
|
32
|
-
const page = await (
|
|
33
|
-
getAssetFromKV as typeof kvAssetHandler.getAssetFromKV
|
|
34
|
-
)(
|
|
35
|
-
{
|
|
36
|
-
request,
|
|
37
|
-
waitUntil(promise: Promise<unknown>) {
|
|
38
|
-
return ctx.waitUntil(promise);
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
options
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
// allow headers to be altered
|
|
45
|
-
const response = new Response(page.body, page);
|
|
46
|
-
|
|
47
|
-
response.headers.set("X-XSS-Protection", "1; mode=block");
|
|
48
|
-
response.headers.set("X-Content-Type-Options", "nosniff");
|
|
49
|
-
response.headers.set("X-Frame-Options", "DENY");
|
|
50
|
-
response.headers.set("Referrer-Policy", "unsafe-url");
|
|
51
|
-
response.headers.set("Feature-Policy", "none");
|
|
52
|
-
|
|
53
|
-
return response;
|
|
54
|
-
} catch (e) {
|
|
55
|
-
if (e instanceof NotFoundError || e instanceof MethodNotAllowedError) {
|
|
56
|
-
// if a known error is thrown then serve from actual worker
|
|
57
|
-
return await worker.fetch(request, env, ctx);
|
|
58
|
-
}
|
|
59
|
-
// otherwise it's a real error, so throw it
|
|
60
|
-
throw e;
|
|
61
|
-
}
|
|
62
|
-
},
|
|
63
|
-
};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import worker from "__ENTRY_POINT__";
|
|
2
|
-
const Workers = __WORKERS__;
|
|
3
|
-
|
|
4
|
-
export * from "__ENTRY_POINT__";
|
|
5
|
-
|
|
6
|
-
export default {
|
|
7
|
-
async fetch(req, env, ctx) {
|
|
8
|
-
const facadeEnv = { ...env };
|
|
9
|
-
// For every Worker definition that's available,
|
|
10
|
-
// create a fetcher for it on the facade env.
|
|
11
|
-
// for const [name, binding] of env
|
|
12
|
-
// if Workers[name]
|
|
13
|
-
// const details = Workers[name];
|
|
14
|
-
|
|
15
|
-
for (const [name, details] of Object.entries(Workers)) {
|
|
16
|
-
if (details) {
|
|
17
|
-
facadeEnv[name] = {
|
|
18
|
-
async fetch(...reqArgs) {
|
|
19
|
-
const reqFromArgs = new Request(...reqArgs);
|
|
20
|
-
if (details.headers) {
|
|
21
|
-
for (const [key, value] of Object.entries(details.headers)) {
|
|
22
|
-
// In remote mode, you need to add a couple of headers
|
|
23
|
-
// to make sure it's talking to the 'dev' preview session
|
|
24
|
-
// (much like wrangler dev already does via proxy.ts)
|
|
25
|
-
reqFromArgs.headers.set(key, value);
|
|
26
|
-
}
|
|
27
|
-
return env[name].fetch(reqFromArgs);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const url = new URL(reqFromArgs.url);
|
|
31
|
-
url.protocol = details.protocol;
|
|
32
|
-
url.host = details.host;
|
|
33
|
-
if (details.port !== undefined) url.port = details.port;
|
|
34
|
-
|
|
35
|
-
const request = new Request(url.toString(), reqFromArgs);
|
|
36
|
-
return fetch(request);
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
} else {
|
|
40
|
-
// This means there's no dev binding available.
|
|
41
|
-
// Let's use whatever's available, or put a shim with a message.
|
|
42
|
-
facadeEnv[name] = facadeEnv[name] || {
|
|
43
|
-
async fetch() {
|
|
44
|
-
return new Response(
|
|
45
|
-
`You should start up wrangler dev --local on the ${name} worker`,
|
|
46
|
-
{ status: 404 }
|
|
47
|
-
);
|
|
48
|
-
},
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return worker.fetch(req, facadeEnv, ctx);
|
|
53
|
-
},
|
|
54
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import "__ENTRY_POINT__";
|
|
2
|
-
const Workers = __WORKERS__;
|
|
3
|
-
|
|
4
|
-
// For every Worker definition that's available,
|
|
5
|
-
// create a fetcher for it on the facade env.
|
|
6
|
-
for (const [name, details] of Object.entries(Workers)) {
|
|
7
|
-
if (details) {
|
|
8
|
-
globalThis[name] = {
|
|
9
|
-
async fetch(...reqArgs) {
|
|
10
|
-
const reqFromArgs = new Request(...reqArgs);
|
|
11
|
-
if (details.headers) {
|
|
12
|
-
for (const [key, value] of Object.entries(details.headers)) {
|
|
13
|
-
// In remote mode, you need to add a couple of headers
|
|
14
|
-
// to make sure it's talking to the 'dev' preview session
|
|
15
|
-
// (much like wrangler dev already does via proxy.ts)
|
|
16
|
-
reqFromArgs.headers.set(key, value);
|
|
17
|
-
}
|
|
18
|
-
return env[name].fetch(reqFromArgs);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const url = new URL(reqFromArgs.url);
|
|
22
|
-
url.protocol = details.protocol;
|
|
23
|
-
url.host = details.host;
|
|
24
|
-
if (details.port !== undefined) url.port = details.port;
|
|
25
|
-
|
|
26
|
-
const request = new Request(url.toString(), reqFromArgs);
|
|
27
|
-
return fetch(request);
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
} else {
|
|
31
|
-
// This means it's a local mode binding
|
|
32
|
-
// but hasn't started up locally yet.
|
|
33
|
-
globalThis[name] = {
|
|
34
|
-
async fetch() {
|
|
35
|
-
return new Response(
|
|
36
|
-
`You should start up wrangler dev --local on the ${name} worker`,
|
|
37
|
-
{ status: 404 }
|
|
38
|
-
);
|
|
39
|
-
},
|
|
40
|
-
};
|
|
41
|
-
}
|
|
42
|
-
}
|