create-cloudflare 0.0.0-dfbf03f87 → 0.0.0-dfea523ea
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/dist/cli.js +490 -463
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/templates/angular/pages/c3.ts +1 -0
- package/templates/astro/pages/c3.ts +1 -0
- package/templates/astro/workers/templates/ts/wrangler.jsonc +1 -1
- package/templates/common/c3.ts +5 -1
- package/templates/docusaurus/pages/c3.ts +1 -0
- package/templates/gatsby/pages/c3.ts +1 -0
- package/templates/hello-world/ts/test/env.d.ts +3 -0
- package/templates/hello-world/ts/worker-configuration.d.ts +6 -2
- package/templates/hello-world-assets-only/c3.ts +2 -2
- package/templates/hello-world-durable-object/c3.ts +4 -1
- package/templates/hello-world-with-assets/c3.ts +7 -3
- package/templates/hello-world-with-assets/js/public/index.html +2 -2
- package/templates/hello-world-with-assets/py/public/index.html +2 -2
- package/templates/hello-world-with-assets/ts/public/index.html +2 -2
- package/templates/hello-world-with-assets/ts/test/env.d.ts +0 -6
- package/templates/hello-world-with-assets/ts/test/tsconfig.json +1 -1
- package/templates/hello-world-with-assets/ts/worker-configuration.d.ts +6 -3
- package/templates/hono/pages/c3.ts +3 -1
- package/templates/hono/pages/templates/wrangler.jsonc +1 -2
- package/templates/next/c3.ts +7 -221
- package/templates/next/pages/c3.ts +225 -0
- package/{templates-experimental/next → templates/next/workers}/c3.ts +6 -7
- package/templates/next/workers/templates/open-next.config.ts +9 -0
- package/{templates-experimental/next → templates/next/workers}/templates/wrangler.jsonc +1 -1
- package/templates/nuxt/pages/c3.ts +1 -0
- package/templates/openapi/c3.ts +5 -1
- package/templates/pre-existing/c3.ts +6 -2
- package/templates/queues/c3.ts +5 -1
- package/templates/qwik/pages/c3.ts +1 -0
- package/templates/react/pages/c3.ts +1 -0
- package/templates/react/workers/js/src/App.jsx +1 -1
- package/templates/react/workers/js/{api → worker}/index.js +1 -1
- package/templates/react/workers/js/wrangler.jsonc +2 -2
- package/templates/react/workers/ts/src/App.tsx +1 -1
- package/templates/react/workers/ts/tsconfig.worker.json +1 -1
- package/templates/react/workers/ts/{api → worker}/index.ts +2 -3
- package/templates/react/workers/ts/wrangler.jsonc +2 -2
- package/templates/remix/pages/c3.ts +1 -0
- package/templates/scheduled/c3.ts +5 -1
- package/templates/scheduled/ts/src/index.ts +7 -0
- package/templates/svelte/pages/c3.ts +1 -0
- package/templates/vue/pages/c3.ts +1 -0
- package/templates/vue/workers/js/server/index.js +2 -2
- package/templates/vue/workers/js/wrangler.jsonc +0 -1
- package/templates/vue/workers/ts/server/index.ts +2 -3
- package/templates/vue/workers/ts/wrangler.jsonc +0 -1
- package/templates-experimental/next/templates/open-next.config.ts +0 -6
- /package/templates/next/{README.md → pages/README.md} +0 -0
- /package/templates/next/{app → pages/app}/js/app/api/hello/route.js +0 -0
- /package/templates/next/{app → pages/app}/js/app/not-found.js +0 -0
- /package/templates/next/{app → pages/app}/ts/app/api/hello/route.ts +0 -0
- /package/templates/next/{app → pages/app}/ts/app/not-found.tsx +0 -0
- /package/templates/next/{env.d.ts → pages/env.d.ts} +0 -0
- /package/templates/next/pages/{js → pages/js}/pages/api/hello.js +0 -0
- /package/templates/next/pages/{ts → pages/ts}/pages/api/hello.ts +0 -0
- /package/templates/next/{wrangler.jsonc → pages/wrangler.jsonc} +0 -0
- /package/{templates-experimental/next → templates/next/workers}/templates/.dev.vars +0 -0
- /package/{templates-experimental/next → templates/next/workers}/templates/__dot__gitignore +0 -0
- /package/{templates-experimental/next → templates/next/workers}/templates/cloudflare-env.d.ts +0 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { updateStatus, warn } from "@cloudflare/cli";
|
|
3
|
+
import { brandColor, dim } from "@cloudflare/cli/colors";
|
|
4
|
+
import { inputPrompt, spinner } from "@cloudflare/cli/interactive";
|
|
5
|
+
import { runFrameworkGenerator } from "frameworks/index";
|
|
6
|
+
import {
|
|
7
|
+
copyFile,
|
|
8
|
+
probePaths,
|
|
9
|
+
readFile,
|
|
10
|
+
readJSON,
|
|
11
|
+
usesEslint,
|
|
12
|
+
usesTypescript,
|
|
13
|
+
writeFile,
|
|
14
|
+
writeJSON,
|
|
15
|
+
} from "helpers/files";
|
|
16
|
+
import { detectPackageManager } from "helpers/packageManagers";
|
|
17
|
+
import { installPackages } from "helpers/packages";
|
|
18
|
+
import { getTemplatePath } from "../../../src/templates";
|
|
19
|
+
import type { TemplateConfig } from "../../../src/templates";
|
|
20
|
+
import type { C3Context } from "types";
|
|
21
|
+
|
|
22
|
+
const { npm, npx } = detectPackageManager();
|
|
23
|
+
|
|
24
|
+
const generate = async (ctx: C3Context) => {
|
|
25
|
+
const projectName = ctx.project.name;
|
|
26
|
+
|
|
27
|
+
await runFrameworkGenerator(ctx, [projectName]);
|
|
28
|
+
|
|
29
|
+
const wranglerConfig = readFile(join(getTemplatePath(ctx), "wrangler.jsonc"));
|
|
30
|
+
writeFile(join(ctx.project.path, "wrangler.jsonc"), wranglerConfig);
|
|
31
|
+
updateStatus("Created wrangler.jsonc file");
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const updateNextConfig = (usesTs: boolean) => {
|
|
35
|
+
const s = spinner();
|
|
36
|
+
|
|
37
|
+
const configFile = `next.config.${usesTs ? "ts" : "mjs"}`;
|
|
38
|
+
s.start(`Updating \`${configFile}\``);
|
|
39
|
+
|
|
40
|
+
const configContent = readFile(configFile);
|
|
41
|
+
|
|
42
|
+
const updatedConfigFile =
|
|
43
|
+
`import { setupDevPlatform } from '@cloudflare/next-on-pages/next-dev';
|
|
44
|
+
|
|
45
|
+
// Here we use the @cloudflare/next-on-pages next-dev module to allow us to
|
|
46
|
+
// use bindings during local development (when running the application with
|
|
47
|
+
// \`next dev\`). This function is only necessary during development and
|
|
48
|
+
// has no impact outside of that. For more information see:
|
|
49
|
+
// https://github.com/cloudflare/next-on-pages/blob/main/internal-packages/next-dev/README.md
|
|
50
|
+
setupDevPlatform().catch(console.error);
|
|
51
|
+
|
|
52
|
+
`.replace(/\n\t*/g, "\n") + configContent;
|
|
53
|
+
|
|
54
|
+
writeFile(configFile, updatedConfigFile);
|
|
55
|
+
|
|
56
|
+
s.stop(`${brandColor(`updated`)} ${dim(`\`${configFile}\``)}`);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const configure = async (ctx: C3Context) => {
|
|
60
|
+
const projectPath = ctx.project.path;
|
|
61
|
+
|
|
62
|
+
// Add a compatible function handler example
|
|
63
|
+
const path = probePaths([
|
|
64
|
+
`${projectPath}/pages/api`,
|
|
65
|
+
`${projectPath}/src/pages/api`,
|
|
66
|
+
`${projectPath}/src/app/api`,
|
|
67
|
+
`${projectPath}/app/api`,
|
|
68
|
+
`${projectPath}/src/app`,
|
|
69
|
+
`${projectPath}/app`,
|
|
70
|
+
]);
|
|
71
|
+
|
|
72
|
+
if (!path) {
|
|
73
|
+
throw new Error("Could not find the `/api` or `/app` directory");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const usesTs = usesTypescript(ctx);
|
|
77
|
+
|
|
78
|
+
if (usesTs) {
|
|
79
|
+
copyFile(
|
|
80
|
+
join(getTemplatePath(ctx), "env.d.ts"),
|
|
81
|
+
join(projectPath, "env.d.ts"),
|
|
82
|
+
);
|
|
83
|
+
updateStatus("Created an env.d.ts file");
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const installEslintPlugin = await shouldInstallNextOnPagesEslintPlugin(ctx);
|
|
87
|
+
|
|
88
|
+
if (installEslintPlugin) {
|
|
89
|
+
await writeEslintrc(ctx);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
updateNextConfig(usesTs);
|
|
93
|
+
|
|
94
|
+
copyFile(
|
|
95
|
+
join(getTemplatePath(ctx), "README.md"),
|
|
96
|
+
join(projectPath, "README.md"),
|
|
97
|
+
);
|
|
98
|
+
updateStatus("Updated the README file");
|
|
99
|
+
|
|
100
|
+
await addDevDependencies(installEslintPlugin);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const shouldInstallNextOnPagesEslintPlugin = async (
|
|
104
|
+
ctx: C3Context,
|
|
105
|
+
): Promise<boolean> => {
|
|
106
|
+
const eslintUsage = usesEslint(ctx);
|
|
107
|
+
|
|
108
|
+
if (!eslintUsage.used) {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (eslintUsage.configType !== ".eslintrc.json") {
|
|
113
|
+
warn(
|
|
114
|
+
`Expected .eslintrc.json from Next.js scaffolding but found ${eslintUsage.configType} instead`,
|
|
115
|
+
);
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return await inputPrompt({
|
|
120
|
+
type: "confirm",
|
|
121
|
+
question: "Do you want to use the next-on-pages eslint-plugin?",
|
|
122
|
+
label: "eslint-plugin",
|
|
123
|
+
defaultValue: true,
|
|
124
|
+
});
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export const writeEslintrc = async (ctx: C3Context): Promise<void> => {
|
|
128
|
+
const eslintConfig = readJSON(`${ctx.project.path}/.eslintrc.json`) as {
|
|
129
|
+
plugins: string[];
|
|
130
|
+
extends: string | string[];
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
eslintConfig.plugins ??= [];
|
|
134
|
+
eslintConfig.plugins.push("eslint-plugin-next-on-pages");
|
|
135
|
+
|
|
136
|
+
if (typeof eslintConfig.extends === "string") {
|
|
137
|
+
eslintConfig.extends = [eslintConfig.extends];
|
|
138
|
+
}
|
|
139
|
+
eslintConfig.extends ??= [];
|
|
140
|
+
eslintConfig.extends.push("plugin:eslint-plugin-next-on-pages/recommended");
|
|
141
|
+
|
|
142
|
+
writeJSON(`${ctx.project.path}/.eslintrc.json`, eslintConfig);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const addDevDependencies = async (installEslintPlugin: boolean) => {
|
|
146
|
+
const packages = [
|
|
147
|
+
"@cloudflare/next-on-pages@1",
|
|
148
|
+
"@cloudflare/workers-types",
|
|
149
|
+
"vercel",
|
|
150
|
+
...(installEslintPlugin ? ["eslint-plugin-next-on-pages"] : []),
|
|
151
|
+
];
|
|
152
|
+
await installPackages(packages, {
|
|
153
|
+
dev: true,
|
|
154
|
+
startText: "Adding the Cloudflare Pages adapter",
|
|
155
|
+
doneText: `${brandColor(`installed`)} ${dim(packages.join(", "))}`,
|
|
156
|
+
});
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
export default {
|
|
160
|
+
configVersion: 1,
|
|
161
|
+
id: "next",
|
|
162
|
+
frameworkCli: "create-next-app",
|
|
163
|
+
platform: "pages",
|
|
164
|
+
hidden: true,
|
|
165
|
+
displayName: "Next.js",
|
|
166
|
+
path: "templates/next/pages",
|
|
167
|
+
generate,
|
|
168
|
+
configure,
|
|
169
|
+
copyFiles: {
|
|
170
|
+
async selectVariant(ctx) {
|
|
171
|
+
const isApp = probePaths([
|
|
172
|
+
`${ctx.project.path}/src/app`,
|
|
173
|
+
`${ctx.project.path}/app`,
|
|
174
|
+
]);
|
|
175
|
+
|
|
176
|
+
const isTypescript = usesTypescript(ctx);
|
|
177
|
+
|
|
178
|
+
const dir = isApp ? "app" : "pages";
|
|
179
|
+
return `${dir}/${isTypescript ? "ts" : "js"}`;
|
|
180
|
+
},
|
|
181
|
+
destinationDir(ctx) {
|
|
182
|
+
const srcPath = probePaths([`${ctx.project.path}/src`]);
|
|
183
|
+
return srcPath ? "./src" : "./";
|
|
184
|
+
},
|
|
185
|
+
variants: {
|
|
186
|
+
"app/ts": {
|
|
187
|
+
path: "./app/ts",
|
|
188
|
+
},
|
|
189
|
+
"app/js": {
|
|
190
|
+
path: "./app/js",
|
|
191
|
+
},
|
|
192
|
+
"pages/ts": {
|
|
193
|
+
path: "./pages/ts",
|
|
194
|
+
},
|
|
195
|
+
"pages/js": {
|
|
196
|
+
path: "./pages/js",
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
transformPackageJson: async (_, ctx) => {
|
|
201
|
+
const isNpm = npm === "npm";
|
|
202
|
+
const isBun = npm === "bun";
|
|
203
|
+
const isNpmOrBun = isNpm || isBun;
|
|
204
|
+
const nextOnPagesScope = isNpmOrBun ? "@cloudflare/" : "";
|
|
205
|
+
const nextOnPagesCommand = `${nextOnPagesScope}next-on-pages`;
|
|
206
|
+
const pmCommand = isNpmOrBun ? npx : npm;
|
|
207
|
+
const pagesBuildRunCommand = `${
|
|
208
|
+
isNpm ? "npm run" : isBun ? "bun" : pmCommand
|
|
209
|
+
} pages:build`;
|
|
210
|
+
return {
|
|
211
|
+
scripts: {
|
|
212
|
+
"pages:build": `${pmCommand} ${nextOnPagesCommand}`,
|
|
213
|
+
preview: `${pagesBuildRunCommand} && wrangler pages dev`,
|
|
214
|
+
deploy: `${pagesBuildRunCommand} && wrangler pages deploy`,
|
|
215
|
+
...(usesTypescript(ctx) && {
|
|
216
|
+
"cf-typegen": `wrangler types --env-interface CloudflareEnv env.d.ts`,
|
|
217
|
+
}),
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
},
|
|
221
|
+
devScript: "dev",
|
|
222
|
+
previewScript: "preview",
|
|
223
|
+
deployScript: "deploy",
|
|
224
|
+
compatibilityFlags: ["nodejs_compat"],
|
|
225
|
+
} as TemplateConfig;
|
|
@@ -3,7 +3,7 @@ import { spinner } from "@cloudflare/cli/interactive";
|
|
|
3
3
|
import { runFrameworkGenerator } from "frameworks/index";
|
|
4
4
|
import { readFile, usesTypescript, writeFile } from "helpers/files";
|
|
5
5
|
import { installPackages } from "helpers/packages";
|
|
6
|
-
import type { TemplateConfig } from "
|
|
6
|
+
import type { TemplateConfig } from "../../../src/templates";
|
|
7
7
|
import type { C3Context } from "types";
|
|
8
8
|
|
|
9
9
|
const generate = async (ctx: C3Context) => {
|
|
@@ -12,7 +12,7 @@ const generate = async (ctx: C3Context) => {
|
|
|
12
12
|
|
|
13
13
|
const configure = async (ctx: C3Context) => {
|
|
14
14
|
const packages = [
|
|
15
|
-
"@opennextjs/cloudflare
|
|
15
|
+
"@opennextjs/cloudflare@~1.0.0-beta.0 || ^1.0.0",
|
|
16
16
|
"@cloudflare/workers-types",
|
|
17
17
|
];
|
|
18
18
|
await installPackages(packages, {
|
|
@@ -51,11 +51,10 @@ export default {
|
|
|
51
51
|
configVersion: 1,
|
|
52
52
|
id: "next",
|
|
53
53
|
frameworkCli: "create-next-app",
|
|
54
|
-
|
|
55
|
-
frameworkCliPinnedVersion: "~15.2.2",
|
|
54
|
+
frameworkCliPinnedVersion: "~15.2.4",
|
|
56
55
|
platform: "workers",
|
|
57
56
|
displayName: "Next.js (using Node.js compat + Workers Assets)",
|
|
58
|
-
path: "templates
|
|
57
|
+
path: "templates/next/workers",
|
|
59
58
|
copyFiles: {
|
|
60
59
|
path: "./templates",
|
|
61
60
|
},
|
|
@@ -63,8 +62,8 @@ export default {
|
|
|
63
62
|
configure,
|
|
64
63
|
transformPackageJson: async () => ({
|
|
65
64
|
scripts: {
|
|
66
|
-
deploy: `opennextjs-cloudflare &&
|
|
67
|
-
preview: `opennextjs-cloudflare &&
|
|
65
|
+
deploy: `opennextjs-cloudflare build && opennextjs-cloudflare deploy`,
|
|
66
|
+
preview: `opennextjs-cloudflare build && opennextjs-cloudflare preview`,
|
|
68
67
|
"cf-typegen": `wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts`,
|
|
69
68
|
},
|
|
70
69
|
}),
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { defineCloudflareConfig } from "@opennextjs/cloudflare";
|
|
2
|
+
|
|
3
|
+
export default defineCloudflareConfig({
|
|
4
|
+
// Uncomment to enable R2 cache,
|
|
5
|
+
// It should be imported as:
|
|
6
|
+
// `import r2IncrementalCache from "@opennextjs/cloudflare/overrides/incremental-cache/r2-incremental-cache";`
|
|
7
|
+
// See https://opennext.js.org/cloudflare/caching for more details
|
|
8
|
+
// incrementalCache: r2IncrementalCache,
|
|
9
|
+
});
|
package/templates/openapi/c3.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
2
|
+
|
|
3
|
+
const config: TemplateConfig = {
|
|
2
4
|
configVersion: 1,
|
|
3
5
|
id: "openapi",
|
|
4
6
|
displayName: "API starter (OpenAPI compliant)",
|
|
@@ -8,3 +10,5 @@ export default {
|
|
|
8
10
|
path: "./ts",
|
|
9
11
|
},
|
|
10
12
|
};
|
|
13
|
+
|
|
14
|
+
export default config;
|
|
@@ -6,6 +6,7 @@ import { processArgument } from "helpers/args";
|
|
|
6
6
|
import { runCommand } from "helpers/command";
|
|
7
7
|
import { detectPackageManager } from "helpers/packageManagers";
|
|
8
8
|
import { chooseAccount, wranglerLogin } from "../../src/wrangler/accounts";
|
|
9
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
9
10
|
import type { C3Context } from "types";
|
|
10
11
|
|
|
11
12
|
export async function copyExistingWorkerFiles(ctx: C3Context) {
|
|
@@ -31,7 +32,7 @@ export async function copyExistingWorkerFiles(ctx: C3Context) {
|
|
|
31
32
|
await runCommand(
|
|
32
33
|
[
|
|
33
34
|
...dlx,
|
|
34
|
-
"wrangler@
|
|
35
|
+
"wrangler@latest",
|
|
35
36
|
"init",
|
|
36
37
|
"--from-dash",
|
|
37
38
|
ctx.args.existingScript,
|
|
@@ -63,10 +64,11 @@ export async function copyExistingWorkerFiles(ctx: C3Context) {
|
|
|
63
64
|
);
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
|
|
67
|
+
const config: TemplateConfig = {
|
|
67
68
|
configVersion: 1,
|
|
68
69
|
id: "pre-existing",
|
|
69
70
|
displayName: "Pre-existing Worker (from Dashboard)",
|
|
71
|
+
description: "Fetch a Worker initialized from the Cloudflare dashboard.",
|
|
70
72
|
platform: "workers",
|
|
71
73
|
hidden: true,
|
|
72
74
|
copyFiles: {
|
|
@@ -79,6 +81,8 @@ export default {
|
|
|
79
81
|
}),
|
|
80
82
|
};
|
|
81
83
|
|
|
84
|
+
export default config;
|
|
85
|
+
|
|
82
86
|
export interface ConfigureParams {
|
|
83
87
|
login: (ctx: C3Context) => Promise<boolean>;
|
|
84
88
|
chooseAccount: (ctx: C3Context) => Promise<void>;
|
package/templates/queues/c3.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
2
|
+
|
|
3
|
+
const config: TemplateConfig = {
|
|
2
4
|
configVersion: 1,
|
|
3
5
|
id: "queues",
|
|
4
6
|
displayName: "Queue consumer & producer Worker",
|
|
@@ -26,3 +28,5 @@ export default {
|
|
|
26
28
|
],
|
|
27
29
|
},
|
|
28
30
|
};
|
|
31
|
+
|
|
32
|
+
export default config;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "<TBD>",
|
|
3
|
-
"main": "
|
|
3
|
+
"main": "worker/index.js",
|
|
4
4
|
"compatibility_date": "<TBD>",
|
|
5
|
-
"assets": { "not_found_handling": "single-page-application"
|
|
5
|
+
"assets": { "not_found_handling": "single-page-application" },
|
|
6
6
|
"observability": {
|
|
7
7
|
"enabled": true
|
|
8
8
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
fetch(request
|
|
2
|
+
fetch(request) {
|
|
3
3
|
const url = new URL(request.url);
|
|
4
4
|
|
|
5
5
|
if (url.pathname.startsWith("/api/")) {
|
|
@@ -7,7 +7,6 @@ export default {
|
|
|
7
7
|
name: "Cloudflare",
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
return env.ASSETS.fetch(request);
|
|
10
|
+
return new Response(null, { status: 404 });
|
|
12
11
|
},
|
|
13
12
|
} satisfies ExportedHandler<Env>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "<TBD>",
|
|
3
|
-
"main": "
|
|
3
|
+
"main": "worker/index.ts",
|
|
4
4
|
"compatibility_date": "<TBD>",
|
|
5
|
-
"assets": { "not_found_handling": "single-page-application"
|
|
5
|
+
"assets": { "not_found_handling": "single-page-application" },
|
|
6
6
|
"observability": {
|
|
7
7
|
"enabled": true
|
|
8
8
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import type { TemplateConfig } from "../../src/templates";
|
|
2
|
+
|
|
3
|
+
const config: TemplateConfig = {
|
|
2
4
|
configVersion: 1,
|
|
3
5
|
id: "scheduled",
|
|
4
6
|
displayName: "Scheduled Worker (Cron Trigger)",
|
|
@@ -16,3 +18,5 @@ export default {
|
|
|
16
18
|
},
|
|
17
19
|
},
|
|
18
20
|
};
|
|
21
|
+
|
|
22
|
+
export default config;
|
|
@@ -16,6 +16,13 @@
|
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
18
|
export default {
|
|
19
|
+
async fetch(req) {
|
|
20
|
+
const url = new URL(req.url);
|
|
21
|
+
url.pathname = '/__scheduled';
|
|
22
|
+
url.searchParams.append('cron', '* * * * *');
|
|
23
|
+
return new Response(`To test the scheduled handler, ensure you have used the "--test-scheduled" then try running "curl ${url.href}".`);
|
|
24
|
+
},
|
|
25
|
+
|
|
19
26
|
// The scheduled handler is invoked at the interval set in our wrangler.jsonc's
|
|
20
27
|
// [[triggers]] configuration.
|
|
21
28
|
async scheduled(event, env, ctx): Promise<void> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
fetch(request
|
|
2
|
+
fetch(request) {
|
|
3
3
|
const url = new URL(request.url);
|
|
4
4
|
|
|
5
5
|
if (url.pathname.startsWith("/api/")) {
|
|
@@ -8,6 +8,6 @@ export default {
|
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
return
|
|
11
|
+
return new Response(null, { status: 404 });
|
|
12
12
|
},
|
|
13
13
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default {
|
|
2
|
-
fetch(request
|
|
2
|
+
fetch(request) {
|
|
3
3
|
const url = new URL(request.url);
|
|
4
4
|
|
|
5
5
|
if (url.pathname.startsWith("/api/")) {
|
|
@@ -7,7 +7,6 @@ export default {
|
|
|
7
7
|
name: "Cloudflare",
|
|
8
8
|
});
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
return env.ASSETS.fetch(request);
|
|
10
|
+
return new Response(null, { status: 404 });
|
|
12
11
|
},
|
|
13
12
|
} satisfies ExportedHandler<Env>;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/{templates-experimental/next → templates/next/workers}/templates/cloudflare-env.d.ts
RENAMED
|
File without changes
|