create-cloudflare 0.0.0-d4b4c3a5 → 0.0.0-d4dae6f6
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 +32980 -32851
- package/package.json +2 -2
- package/templates/angular/c3.ts +10 -9
- package/templates/astro/c3.ts +3 -11
- package/templates/astro/templates/wrangler.toml +30 -28
- package/templates/common/js/.editorconfig +0 -1
- package/templates/common/js/wrangler.toml +68 -22
- package/templates/common/ts/.editorconfig +0 -1
- package/templates/common/ts/wrangler.toml +68 -22
- package/templates/docusaurus/c3.ts +5 -6
- package/templates/gatsby/c3.ts +7 -5
- package/templates/hello-world/js/.editorconfig +0 -1
- package/templates/hello-world/js/package.json +3 -1
- package/templates/hello-world/js/test/index.spec.js +20 -0
- package/templates/hello-world/js/vitest.config.js +11 -0
- package/templates/hello-world/js/wrangler.toml +69 -22
- package/templates/hello-world/ts/.editorconfig +0 -1
- package/templates/hello-world/ts/package.json +5 -2
- package/templates/hello-world/ts/test/index.spec.ts +25 -0
- package/templates/hello-world/ts/test/tsconfig.json +11 -0
- package/templates/hello-world/ts/tsconfig.json +3 -2
- package/templates/hello-world/ts/vitest.config.ts +11 -0
- package/templates/hello-world/ts/wrangler.toml +69 -22
- package/templates/hello-world-durable-object/js/.editorconfig +0 -1
- package/templates/hello-world-durable-object/js/wrangler.toml +69 -23
- package/templates/hello-world-durable-object/ts/.editorconfig +0 -1
- package/templates/hello-world-durable-object/ts/wrangler.toml +68 -21
- package/templates/hono/c3.ts +1 -1
- package/templates/next/README.md +11 -1
- package/templates/next/app/js/app/api/hello/route.js +1 -1
- package/templates/next/app/ts/app/api/hello/route.ts +1 -1
- package/templates/next/c3.ts +29 -19
- package/templates/next/env.d.ts +3 -5
- package/templates/next/pages/js/pages/api/hello.js +1 -1
- package/templates/next/pages/ts/pages/api/hello.ts +1 -1
- package/templates/next/wrangler.toml +29 -32
- package/templates/nuxt/c3.ts +42 -8
- package/templates/nuxt/templates/env.d.ts +14 -0
- package/templates/nuxt/templates/worker-configuration.d.ts +4 -0
- package/templates/nuxt/templates/wrangler.toml +30 -28
- package/templates/pre-existing/c3.ts +2 -2
- package/templates/pre-existing/js/.editorconfig +0 -1
- package/templates/queues/js/.editorconfig +0 -1
- package/templates/queues/js/wrangler.toml +85 -2
- package/templates/queues/ts/.editorconfig +0 -1
- package/templates/queues/ts/wrangler.toml +85 -2
- package/templates/qwik/c3.ts +6 -5
- package/templates/qwik/templates/worker-configuration.d.ts +3 -2
- package/templates/qwik/templates/wrangler.toml +30 -28
- package/templates/react/c3.ts +7 -5
- package/templates/remix/c3.ts +3 -4
- package/templates/remix/templates/worker-configuration.d.ts +3 -2
- package/templates/remix/templates/wrangler.toml +30 -28
- package/templates/scheduled/js/.editorconfig +0 -1
- package/templates/scheduled/js/wrangler.toml +94 -0
- package/templates/scheduled/ts/.editorconfig +0 -1
- package/templates/scheduled/ts/wrangler.toml +94 -0
- package/templates/solid/c3.ts +58 -15
- package/templates/svelte/c3.ts +3 -2
- package/templates/svelte/js/wrangler.toml +30 -28
- package/templates/svelte/ts/wrangler.toml +30 -28
- package/templates/vue/c3.ts +7 -6
- package/templates/solid/js/vite.config.js +0 -12
- package/templates/solid/ts/vite.config.ts +0 -12
- package/templates/svelte/js/src/hooks.server.js +0 -25
- package/templates/svelte/ts/src/hooks.server.ts +0 -24
|
@@ -5,10 +5,13 @@
|
|
|
5
5
|
"scripts": {
|
|
6
6
|
"deploy": "wrangler deploy",
|
|
7
7
|
"dev": "wrangler dev",
|
|
8
|
-
"start": "wrangler dev"
|
|
8
|
+
"start": "wrangler dev",
|
|
9
|
+
"test": "vitest"
|
|
9
10
|
},
|
|
10
11
|
"devDependencies": {
|
|
11
12
|
"typescript": "^5.0.4",
|
|
12
|
-
"wrangler": "^3.0.0"
|
|
13
|
+
"wrangler": "^3.0.0",
|
|
14
|
+
"vitest": "1.3.0",
|
|
15
|
+
"@cloudflare/vitest-pool-workers": "^0.1.0"
|
|
13
16
|
}
|
|
14
17
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// test/index.spec.ts
|
|
2
|
+
import { env, createExecutionContext, waitOnExecutionContext, SELF } from "cloudflare:test";
|
|
3
|
+
import { describe, it, expect } from "vitest";
|
|
4
|
+
import worker from "../src/index";
|
|
5
|
+
|
|
6
|
+
// For now, you'll need to do something like this to get a correctly-typed
|
|
7
|
+
// `Request` to pass to `worker.fetch()`.
|
|
8
|
+
const IncomingRequest = Request<unknown, IncomingRequestCfProperties>;
|
|
9
|
+
|
|
10
|
+
describe("Hello World worker", () => {
|
|
11
|
+
it("responds with Hello World! (unit style)", async () => {
|
|
12
|
+
const request = new IncomingRequest("http://example.com");
|
|
13
|
+
// Create an empty context to pass to `worker.fetch()`.
|
|
14
|
+
const ctx = createExecutionContext();
|
|
15
|
+
const response = await worker.fetch(request, env, ctx);
|
|
16
|
+
// Wait for all `Promise`s passed to `ctx.waitUntil()` to settle before running test assertions
|
|
17
|
+
await waitOnExecutionContext(ctx);
|
|
18
|
+
expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("responds with Hello World! (integration style)", async () => {
|
|
22
|
+
const response = await SELF.fetch("https://example.com");
|
|
23
|
+
expect(await response.text()).toMatchInlineSnapshot(`"Hello World!"`);
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
/* Modules */
|
|
27
27
|
"module": "es2022" /* Specify what module code is generated. */,
|
|
28
28
|
// "rootDir": "./", /* Specify the root folder within your source files. */
|
|
29
|
-
"moduleResolution": "
|
|
29
|
+
"moduleResolution": "Bundler" /* Specify how TypeScript looks up a file from a given module specifier. */,
|
|
30
30
|
// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
|
|
31
31
|
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
|
32
32
|
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
|
@@ -97,5 +97,6 @@
|
|
|
97
97
|
/* Completeness */
|
|
98
98
|
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
99
99
|
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
100
|
-
}
|
|
100
|
+
},
|
|
101
|
+
"exclude": ["test"]
|
|
101
102
|
}
|
|
@@ -1,51 +1,98 @@
|
|
|
1
1
|
name = "<TBD>"
|
|
2
2
|
main = "src/index.ts"
|
|
3
3
|
compatibility_date = "<TBD>"
|
|
4
|
+
compatibility_flags = ["nodejs_compat"]
|
|
4
5
|
|
|
5
6
|
# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
|
|
6
7
|
# Note: Use secrets to store sensitive data.
|
|
7
|
-
# Docs: https://developers.cloudflare.com/workers/
|
|
8
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
|
|
8
9
|
# [vars]
|
|
9
10
|
# MY_VARIABLE = "production_value"
|
|
10
11
|
|
|
12
|
+
# Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
|
|
13
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#workers-ai
|
|
14
|
+
# [ai]
|
|
15
|
+
# binding = "AI"
|
|
16
|
+
|
|
17
|
+
# Bind an Analytics Engine dataset. Use Analytics Engine to write analytics within your Pages Function.
|
|
18
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#analytics-engine-datasets
|
|
19
|
+
# [[analytics_engine_datasets]]
|
|
20
|
+
# binding = "MY_DATASET"
|
|
21
|
+
|
|
22
|
+
# Bind a headless browser instance running on Cloudflare's global network.
|
|
23
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#browser-rendering
|
|
24
|
+
# [browser]
|
|
25
|
+
# binding = "MY_BROWSER"
|
|
26
|
+
|
|
27
|
+
# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
|
|
28
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
|
|
29
|
+
# [[d1_databases]]
|
|
30
|
+
# binding = "MY_DB"
|
|
31
|
+
# database_name = "my-database"
|
|
32
|
+
# database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
33
|
+
|
|
34
|
+
# Bind a dispatch namespace. Use Workers for Platforms to deploy serverless functions programmatically on behalf of your customers.
|
|
35
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#dispatch-namespace-bindings-workers-for-platforms
|
|
36
|
+
# [[dispatch_namespaces]]
|
|
37
|
+
# binding = "MY_DISPATCHER"
|
|
38
|
+
# namespace = "my-namespace"
|
|
39
|
+
|
|
40
|
+
# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
|
|
41
|
+
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
|
|
42
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
|
|
43
|
+
# [[durable_objects.bindings]]
|
|
44
|
+
# name = "MY_DURABLE_OBJECT"
|
|
45
|
+
# class_name = "MyDurableObject"
|
|
46
|
+
|
|
47
|
+
# Durable Object migrations.
|
|
48
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#migrations
|
|
49
|
+
# [[migrations]]
|
|
50
|
+
# tag = "v1"
|
|
51
|
+
# new_classes = ["MyDurableObject"]
|
|
52
|
+
|
|
53
|
+
# Bind a Hyperdrive configuration. Use to accelerate access to your existing databases from Cloudflare Workers.
|
|
54
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#hyperdrive
|
|
55
|
+
# [[hyperdrive]]
|
|
56
|
+
# binding = "MY_HYPERDRIVE"
|
|
57
|
+
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
58
|
+
|
|
11
59
|
# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
|
|
12
|
-
# Docs: https://developers.cloudflare.com/workers/
|
|
60
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#kv-namespaces
|
|
13
61
|
# [[kv_namespaces]]
|
|
14
62
|
# binding = "MY_KV_NAMESPACE"
|
|
15
63
|
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
16
64
|
|
|
17
|
-
# Bind an
|
|
18
|
-
# Docs: https://developers.cloudflare.com/
|
|
19
|
-
# [[
|
|
20
|
-
# binding = "
|
|
21
|
-
#
|
|
65
|
+
# Bind an mTLS certificate. Use to present a client certificate when communicating with another service.
|
|
66
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#mtls-certificates
|
|
67
|
+
# [[mtls_certificates]]
|
|
68
|
+
# binding = "MY_CERTIFICATE"
|
|
69
|
+
# certificate_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
22
70
|
|
|
23
71
|
# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
|
|
24
|
-
# Docs: https://developers.cloudflare.com/queues
|
|
72
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
|
|
25
73
|
# [[queues.producers]]
|
|
26
74
|
# binding = "MY_QUEUE"
|
|
27
75
|
# queue = "my-queue"
|
|
28
76
|
|
|
29
77
|
# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
|
|
30
|
-
# Docs: https://developers.cloudflare.com/queues
|
|
78
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
|
|
31
79
|
# [[queues.consumers]]
|
|
32
80
|
# queue = "my-queue"
|
|
33
81
|
|
|
82
|
+
# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
|
|
83
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#r2-buckets
|
|
84
|
+
# [[r2_buckets]]
|
|
85
|
+
# binding = "MY_BUCKET"
|
|
86
|
+
# bucket_name = "my-bucket"
|
|
87
|
+
|
|
34
88
|
# Bind another Worker service. Use this binding to call another Worker without network overhead.
|
|
35
|
-
# Docs: https://developers.cloudflare.com/workers/
|
|
89
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
|
|
36
90
|
# [[services]]
|
|
37
91
|
# binding = "MY_SERVICE"
|
|
38
92
|
# service = "my-service"
|
|
39
93
|
|
|
40
|
-
# Bind a
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
# class_name = "MyDurableObject"
|
|
46
|
-
|
|
47
|
-
# Durable Object migrations.
|
|
48
|
-
# Docs: https://developers.cloudflare.com/workers/learning/using-durable-objects#configure-durable-object-classes-with-migrations
|
|
49
|
-
# [[migrations]]
|
|
50
|
-
# tag = "v1"
|
|
51
|
-
# new_classes = ["MyDurableObject"]
|
|
94
|
+
# Bind a Vectorize index. Use to store and query vector embeddings for semantic search, classification and other vector search use-cases.
|
|
95
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#vectorize-indexes
|
|
96
|
+
# [[vectorize]]
|
|
97
|
+
# binding = "MY_INDEX"
|
|
98
|
+
# index_name = "my-index"
|
|
@@ -1,51 +1,97 @@
|
|
|
1
1
|
name = "<TBD>"
|
|
2
|
-
main = "src/index.
|
|
2
|
+
main = "src/index.ts"
|
|
3
3
|
compatibility_date = "<TBD>"
|
|
4
4
|
|
|
5
5
|
# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
|
|
6
6
|
# Note: Use secrets to store sensitive data.
|
|
7
|
-
# Docs: https://developers.cloudflare.com/workers/
|
|
7
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
|
|
8
8
|
# [vars]
|
|
9
9
|
# MY_VARIABLE = "production_value"
|
|
10
10
|
|
|
11
|
+
# Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
|
|
12
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#workers-ai
|
|
13
|
+
# [ai]
|
|
14
|
+
# binding = "AI"
|
|
15
|
+
|
|
16
|
+
# Bind an Analytics Engine dataset. Use Analytics Engine to write analytics within your Pages Function.
|
|
17
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#analytics-engine-datasets
|
|
18
|
+
# [[analytics_engine_datasets]]
|
|
19
|
+
# binding = "MY_DATASET"
|
|
20
|
+
|
|
21
|
+
# Bind a headless browser instance running on Cloudflare's global network.
|
|
22
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#browser-rendering
|
|
23
|
+
# [browser]
|
|
24
|
+
# binding = "MY_BROWSER"
|
|
25
|
+
|
|
26
|
+
# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
|
|
27
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
|
|
28
|
+
# [[d1_databases]]
|
|
29
|
+
# binding = "MY_DB"
|
|
30
|
+
# database_name = "my-database"
|
|
31
|
+
# database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
32
|
+
|
|
33
|
+
# Bind a dispatch namespace. Use Workers for Platforms to deploy serverless functions programmatically on behalf of your customers.
|
|
34
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#dispatch-namespace-bindings-workers-for-platforms
|
|
35
|
+
# [[dispatch_namespaces]]
|
|
36
|
+
# binding = "MY_DISPATCHER"
|
|
37
|
+
# namespace = "my-namespace"
|
|
38
|
+
|
|
39
|
+
# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
|
|
40
|
+
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
|
|
41
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#durable-objects
|
|
42
|
+
[[durable_objects.bindings]]
|
|
43
|
+
name = "MY_DURABLE_OBJECT"
|
|
44
|
+
class_name = "MyDurableObject"
|
|
45
|
+
|
|
46
|
+
# Durable Object migrations.
|
|
47
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#migrations
|
|
48
|
+
[[migrations]]
|
|
49
|
+
tag = "v1"
|
|
50
|
+
new_classes = ["MyDurableObject"]
|
|
51
|
+
|
|
52
|
+
# Bind a Hyperdrive configuration. Use to accelerate access to your existing databases from Cloudflare Workers.
|
|
53
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#hyperdrive
|
|
54
|
+
# [[hyperdrive]]
|
|
55
|
+
# binding = "MY_HYPERDRIVE"
|
|
56
|
+
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
57
|
+
|
|
11
58
|
# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
|
|
12
|
-
# Docs: https://developers.cloudflare.com/workers/
|
|
59
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#kv-namespaces
|
|
13
60
|
# [[kv_namespaces]]
|
|
14
61
|
# binding = "MY_KV_NAMESPACE"
|
|
15
62
|
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
16
63
|
|
|
17
|
-
# Bind an
|
|
18
|
-
# Docs: https://developers.cloudflare.com/
|
|
19
|
-
# [[
|
|
20
|
-
# binding = "
|
|
21
|
-
#
|
|
64
|
+
# Bind an mTLS certificate. Use to present a client certificate when communicating with another service.
|
|
65
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#mtls-certificates
|
|
66
|
+
# [[mtls_certificates]]
|
|
67
|
+
# binding = "MY_CERTIFICATE"
|
|
68
|
+
# certificate_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
22
69
|
|
|
23
70
|
# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
|
|
24
|
-
# Docs: https://developers.cloudflare.com/queues
|
|
71
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
|
|
25
72
|
# [[queues.producers]]
|
|
26
73
|
# binding = "MY_QUEUE"
|
|
27
74
|
# queue = "my-queue"
|
|
28
75
|
|
|
29
76
|
# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
|
|
30
|
-
# Docs: https://developers.cloudflare.com/queues
|
|
77
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
|
|
31
78
|
# [[queues.consumers]]
|
|
32
79
|
# queue = "my-queue"
|
|
33
80
|
|
|
81
|
+
# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
|
|
82
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#r2-buckets
|
|
83
|
+
# [[r2_buckets]]
|
|
84
|
+
# binding = "MY_BUCKET"
|
|
85
|
+
# bucket_name = "my-bucket"
|
|
86
|
+
|
|
34
87
|
# Bind another Worker service. Use this binding to call another Worker without network overhead.
|
|
35
|
-
# Docs: https://developers.cloudflare.com/workers/
|
|
88
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
|
|
36
89
|
# [[services]]
|
|
37
90
|
# binding = "MY_SERVICE"
|
|
38
91
|
# service = "my-service"
|
|
39
92
|
|
|
40
|
-
# Bind a
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
class_name = "MyDurableObject"
|
|
46
|
-
|
|
47
|
-
# Durable Object migrations.
|
|
48
|
-
# Docs: https://developers.cloudflare.com/workers/learning/using-durable-objects#configure-durable-object-classes-with-migrations
|
|
49
|
-
[[migrations]]
|
|
50
|
-
tag = "v1"
|
|
51
|
-
new_classes = ["MyDurableObject"]
|
|
93
|
+
# Bind a Vectorize index. Use to store and query vector embeddings for semantic search, classification and other vector search use-cases.
|
|
94
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#vectorize-indexes
|
|
95
|
+
# [[vectorize]]
|
|
96
|
+
# binding = "MY_INDEX"
|
|
97
|
+
# index_name = "my-index"
|
|
@@ -4,48 +4,95 @@ compatibility_date = "<TBD>"
|
|
|
4
4
|
|
|
5
5
|
# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
|
|
6
6
|
# Note: Use secrets to store sensitive data.
|
|
7
|
-
# Docs: https://developers.cloudflare.com/workers/
|
|
7
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#environment-variables
|
|
8
8
|
# [vars]
|
|
9
9
|
# MY_VARIABLE = "production_value"
|
|
10
10
|
|
|
11
|
+
# Bind the Workers AI model catalog. Run machine learning models, powered by serverless GPUs, on Cloudflare’s global network
|
|
12
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#workers-ai
|
|
13
|
+
# [ai]
|
|
14
|
+
# binding = "AI"
|
|
15
|
+
|
|
16
|
+
# Bind an Analytics Engine dataset. Use Analytics Engine to write analytics within your Pages Function.
|
|
17
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#analytics-engine-datasets
|
|
18
|
+
# [[analytics_engine_datasets]]
|
|
19
|
+
# binding = "MY_DATASET"
|
|
20
|
+
|
|
21
|
+
# Bind a headless browser instance running on Cloudflare's global network.
|
|
22
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#browser-rendering
|
|
23
|
+
# [browser]
|
|
24
|
+
# binding = "MY_BROWSER"
|
|
25
|
+
|
|
26
|
+
# Bind a D1 database. D1 is Cloudflare’s native serverless SQL database.
|
|
27
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#d1-databases
|
|
28
|
+
# [[d1_databases]]
|
|
29
|
+
# binding = "MY_DB"
|
|
30
|
+
# database_name = "my-database"
|
|
31
|
+
# database_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
32
|
+
|
|
33
|
+
# Bind a dispatch namespace. Use Workers for Platforms to deploy serverless functions programmatically on behalf of your customers.
|
|
34
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#dispatch-namespace-bindings-workers-for-platforms
|
|
35
|
+
# [[dispatch_namespaces]]
|
|
36
|
+
# binding = "MY_DISPATCHER"
|
|
37
|
+
# namespace = "my-namespace"
|
|
38
|
+
|
|
39
|
+
# Bind a Durable Object. Durable objects are a scale-to-zero compute primitive based on the actor model.
|
|
40
|
+
# Durable Objects can live for as long as needed. Use these when you need a long-running "server", such as in realtime apps.
|
|
41
|
+
# Docs: https://developers.cloudflare.com/workers/runtime-apis/durable-objects
|
|
42
|
+
[[durable_objects.bindings]]
|
|
43
|
+
name = "MY_DURABLE_OBJECT"
|
|
44
|
+
class_name = "MyDurableObject"
|
|
45
|
+
|
|
46
|
+
# Durable Object migrations.
|
|
47
|
+
# Docs: https://developers.cloudflare.com/workers/learning/using-durable-objects#configure-durable-object-classes-with-migrations
|
|
48
|
+
[[migrations]]
|
|
49
|
+
tag = "v1"
|
|
50
|
+
new_classes = ["MyDurableObject"]
|
|
51
|
+
|
|
52
|
+
# Bind a Hyperdrive configuration. Use to accelerate access to your existing databases from Cloudflare Workers.
|
|
53
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#hyperdrive
|
|
54
|
+
# [[hyperdrive]]
|
|
55
|
+
# binding = "MY_HYPERDRIVE"
|
|
56
|
+
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
57
|
+
|
|
11
58
|
# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
|
|
12
|
-
# Docs: https://developers.cloudflare.com/workers/
|
|
59
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#kv-namespaces
|
|
13
60
|
# [[kv_namespaces]]
|
|
14
61
|
# binding = "MY_KV_NAMESPACE"
|
|
15
62
|
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
16
63
|
|
|
17
|
-
# Bind an
|
|
18
|
-
# Docs: https://developers.cloudflare.com/
|
|
19
|
-
# [[
|
|
20
|
-
# binding = "
|
|
21
|
-
#
|
|
64
|
+
# Bind an mTLS certificate. Use to present a client certificate when communicating with another service.
|
|
65
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#mtls-certificates
|
|
66
|
+
# [[mtls_certificates]]
|
|
67
|
+
# binding = "MY_CERTIFICATE"
|
|
68
|
+
# certificate_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
22
69
|
|
|
23
70
|
# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
|
|
24
|
-
# Docs: https://developers.cloudflare.com/queues
|
|
71
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
|
|
25
72
|
# [[queues.producers]]
|
|
26
73
|
# binding = "MY_QUEUE"
|
|
27
74
|
# queue = "my-queue"
|
|
28
75
|
|
|
29
76
|
# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
|
|
30
|
-
# Docs: https://developers.cloudflare.com/queues
|
|
77
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#queues
|
|
31
78
|
# [[queues.consumers]]
|
|
32
79
|
# queue = "my-queue"
|
|
33
80
|
|
|
81
|
+
# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
|
|
82
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#r2-buckets
|
|
83
|
+
# [[r2_buckets]]
|
|
84
|
+
# binding = "MY_BUCKET"
|
|
85
|
+
# bucket_name = "my-bucket"
|
|
86
|
+
|
|
34
87
|
# Bind another Worker service. Use this binding to call another Worker without network overhead.
|
|
35
|
-
# Docs: https://developers.cloudflare.com/workers/
|
|
88
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#service-bindings
|
|
36
89
|
# [[services]]
|
|
37
90
|
# binding = "MY_SERVICE"
|
|
38
91
|
# service = "my-service"
|
|
39
92
|
|
|
40
|
-
# Bind a
|
|
41
|
-
#
|
|
42
|
-
#
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
class_name = "MyDurableObject"
|
|
93
|
+
# Bind a Vectorize index. Use to store and query vector embeddings for semantic search, classification and other vector search use-cases.
|
|
94
|
+
# Docs: https://developers.cloudflare.com/workers/wrangler/configuration/#vectorize-indexes
|
|
95
|
+
# [[vectorize]]
|
|
96
|
+
# binding = "MY_INDEX"
|
|
97
|
+
# index_name = "my-index"
|
|
46
98
|
|
|
47
|
-
# Durable Object migrations.
|
|
48
|
-
# Docs: https://developers.cloudflare.com/workers/learning/using-durable-objects#configure-durable-object-classes-with-migrations
|
|
49
|
-
[[migrations]]
|
|
50
|
-
tag = "v1"
|
|
51
|
-
new_classes = ["MyDurableObject"]
|
package/templates/hono/c3.ts
CHANGED
package/templates/next/README.md
CHANGED
|
@@ -52,7 +52,17 @@ In order to enable the example:
|
|
|
52
52
|
```
|
|
53
53
|
# KV Example:
|
|
54
54
|
```
|
|
55
|
+
- If you're using TypeScript run the `build-cf-types` script to update the `env.d.ts` file:
|
|
56
|
+
```bash
|
|
57
|
+
npm run build-cf-types
|
|
58
|
+
# or
|
|
59
|
+
yarn build-cf-types
|
|
60
|
+
# or
|
|
61
|
+
pnpm build-cf-types
|
|
62
|
+
# or
|
|
63
|
+
bun build-cf-types
|
|
64
|
+
```
|
|
55
65
|
|
|
56
66
|
After doing this you can run the `dev` or `preview` script and visit the `/api/hello` route to see the example in action.
|
|
57
67
|
|
|
58
|
-
Finally, if you also want to see the example work in the deployed application make sure to add a `
|
|
68
|
+
Finally, if you also want to see the example work in the deployed application make sure to add a `MY_KV_NAMESPACE` binding to your Pages application in its [dashboard kv bindings settings section](https://dash.cloudflare.com/?to=/:account/pages/view/:pages-project/settings/functions#kv_namespace_bindings_section). After having configured it make sure to re-deploy your application.
|
|
@@ -12,7 +12,7 @@ export async function GET(request) {
|
|
|
12
12
|
// )
|
|
13
13
|
//
|
|
14
14
|
// KV Example:
|
|
15
|
-
// const myKv = getRequestContext().env.
|
|
15
|
+
// const myKv = getRequestContext().env.MY_KV_NAMESPACE
|
|
16
16
|
// await myKv.put('suffix', ' from a KV store!')
|
|
17
17
|
// const suffix = await myKv.get('suffix')
|
|
18
18
|
// responseText += suffix
|
|
@@ -13,7 +13,7 @@ export async function GET(request: NextRequest) {
|
|
|
13
13
|
// )
|
|
14
14
|
//
|
|
15
15
|
// KV Example:
|
|
16
|
-
// const myKv = getRequestContext().env.
|
|
16
|
+
// const myKv = getRequestContext().env.MY_KV_NAMESPACE
|
|
17
17
|
// await myKv.put('suffix', ' from a KV store!')
|
|
18
18
|
// const suffix = await myKv.get('suffix')
|
|
19
19
|
// responseText += suffix
|
package/templates/next/c3.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { crash, updateStatus, warn } from "@cloudflare/cli";
|
|
|
3
3
|
import { processArgument } from "@cloudflare/cli/args";
|
|
4
4
|
import { brandColor, dim } from "@cloudflare/cli/colors";
|
|
5
5
|
import { spinner } from "@cloudflare/cli/interactive";
|
|
6
|
-
import {
|
|
6
|
+
import { runFrameworkGenerator } from "frameworks/index";
|
|
7
7
|
import {
|
|
8
8
|
copyFile,
|
|
9
9
|
probePaths,
|
|
@@ -14,7 +14,8 @@ import {
|
|
|
14
14
|
writeFile,
|
|
15
15
|
writeJSON,
|
|
16
16
|
} from "helpers/files";
|
|
17
|
-
import { detectPackageManager } from "helpers/
|
|
17
|
+
import { detectPackageManager } from "helpers/packageManagers";
|
|
18
|
+
import { installPackages } from "helpers/packages";
|
|
18
19
|
import { getTemplatePath } from "../../src/templates";
|
|
19
20
|
import type { TemplateConfig } from "../../src/templates";
|
|
20
21
|
import type { C3Args, C3Context } from "types";
|
|
@@ -26,10 +27,26 @@ const generate = async (ctx: C3Context) => {
|
|
|
26
27
|
|
|
27
28
|
await runFrameworkGenerator(ctx, [projectName]);
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const wranglerToml = readFile(join(getTemplatePath(ctx), "wrangler.toml"));
|
|
31
|
+
|
|
32
|
+
// Note: here we add `# KV Example:` to the toml file for the KV example, we don't actually
|
|
33
|
+
// include the comment in the template wrangler.toml file just so to keep it identical
|
|
34
|
+
// and consistent with that of all the other frameworks
|
|
35
|
+
// (instead of making it a special case which needs extra care)
|
|
36
|
+
const newTomlContent = wranglerToml.replace(
|
|
37
|
+
/#\s+\[\[kv_namespaces\]\]\n#\s+binding\s+=\s+"MY_KV_NAMESPACE"\n#\s+id\s+=\s+"[a-zA-Z0-9]+?"/,
|
|
38
|
+
($1) => `# KV Example:\n${$1}`
|
|
32
39
|
);
|
|
40
|
+
|
|
41
|
+
if (!/# KV Example/.test(newTomlContent)) {
|
|
42
|
+
// This should never happen to users, it is a check mostly so that
|
|
43
|
+
// if the toml file is changed in a way that breaks the "KV Example" addition
|
|
44
|
+
// the C3 Next.js e2e runs will fail with this
|
|
45
|
+
crash("Failed to properly generate the wrangler.toml file");
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
writeFile(join(ctx.project.path, "wrangler.toml"), newTomlContent);
|
|
49
|
+
|
|
33
50
|
updateStatus("Created wrangler.toml file");
|
|
34
51
|
};
|
|
35
52
|
|
|
@@ -158,9 +175,6 @@ export default {
|
|
|
158
175
|
id: "next",
|
|
159
176
|
platform: "pages",
|
|
160
177
|
displayName: "Next",
|
|
161
|
-
devScript: "dev",
|
|
162
|
-
previewScript: "preview",
|
|
163
|
-
deployScript: "deploy",
|
|
164
178
|
generate,
|
|
165
179
|
configure,
|
|
166
180
|
copyFiles: {
|
|
@@ -194,7 +208,7 @@ export default {
|
|
|
194
208
|
},
|
|
195
209
|
},
|
|
196
210
|
},
|
|
197
|
-
transformPackageJson: async () => {
|
|
211
|
+
transformPackageJson: async (_, ctx) => {
|
|
198
212
|
const isNpm = npm === "npm";
|
|
199
213
|
const isBun = npm === "bun";
|
|
200
214
|
const isNpmOrBun = isNpm || isBun;
|
|
@@ -209,18 +223,14 @@ export default {
|
|
|
209
223
|
"pages:build": `${pmCommand} ${nextOnPagesCommand}`,
|
|
210
224
|
preview: `${pagesBuildRunCommand} && wrangler pages dev .vercel/output/static`,
|
|
211
225
|
deploy: `${pagesBuildRunCommand} && wrangler pages deploy .vercel/output/static`,
|
|
226
|
+
...(usesTypescript(ctx) && {
|
|
227
|
+
"build-cf-types": `wrangler types --env-interface CloudflareEnv env.d.ts`,
|
|
228
|
+
}),
|
|
212
229
|
},
|
|
213
230
|
};
|
|
214
231
|
},
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
"--eslint",
|
|
219
|
-
"--tailwind",
|
|
220
|
-
"--src-dir",
|
|
221
|
-
"--app",
|
|
222
|
-
"--import-alias",
|
|
223
|
-
"@/*",
|
|
224
|
-
],
|
|
232
|
+
devScript: "dev",
|
|
233
|
+
previewScript: "preview",
|
|
234
|
+
deployScript: "deploy",
|
|
225
235
|
compatibilityFlags: ["nodejs_compat"],
|
|
226
236
|
} as TemplateConfig;
|
package/templates/next/env.d.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
+
// Generated by Wrangler
|
|
2
|
+
// by running `wrangler types --env-interface CloudflareEnv env.d.ts`
|
|
3
|
+
|
|
1
4
|
interface CloudflareEnv {
|
|
2
|
-
// Add here the Cloudflare Bindings you want to have available in your application
|
|
3
|
-
// (for more details on Bindings see: https://developers.cloudflare.com/pages/functions/bindings/)
|
|
4
|
-
//
|
|
5
|
-
// KV Example:
|
|
6
|
-
// MY_KV: KVNamespace
|
|
7
5
|
}
|
|
@@ -14,7 +14,7 @@ export default async function handler(req) {
|
|
|
14
14
|
// )
|
|
15
15
|
//
|
|
16
16
|
// KV Example:
|
|
17
|
-
// const myKv = getRequestContext().env.
|
|
17
|
+
// const myKv = getRequestContext().env.MY_KV_NAMESPACE
|
|
18
18
|
// await myKv.put('suffix', ' from a KV store!')
|
|
19
19
|
// const suffix = await myKv.get('suffix')
|
|
20
20
|
// responseText += suffix
|
|
@@ -15,7 +15,7 @@ export default async function handler(req: NextRequest) {
|
|
|
15
15
|
// )
|
|
16
16
|
//
|
|
17
17
|
// KV Example:
|
|
18
|
-
// const myKv = getRequestContext().env.
|
|
18
|
+
// const myKv = getRequestContext().env.MY_KV_NAMESPACE
|
|
19
19
|
// await myKv.put('suffix', ' from a KV store!')
|
|
20
20
|
// const suffix = await myKv.get('suffix')
|
|
21
21
|
// responseText += suffix
|