create-cloudflare 0.0.0-96c8cfb9 → 0.0.0-96e4e165
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 +3112 -1651
- package/package.json +7 -5
- package/templates/astro/c3.ts +78 -8
- package/templates/astro/snippets/runtimeDeclaration.ts +4 -0
- package/templates/astro/templates/wrangler.toml +50 -0
- package/templates/common/c3.ts +7 -5
- package/templates/hello-world/c3.ts +7 -5
- package/templates/hello-world-durable-object/c3.ts +7 -5
- package/templates/next/README.md +58 -0
- package/templates/next/app/js/app/api/hello/route.js +21 -0
- package/templates/next/app/js/app/not-found.js +58 -0
- package/templates/next/app/ts/app/api/hello/route.ts +22 -0
- package/templates/next/app/ts/app/not-found.tsx +58 -0
- package/templates/next/c3.ts +75 -62
- package/templates/next/env.d.ts +7 -0
- package/templates/next/pages/js/pages/api/hello.js +23 -0
- package/templates/next/pages/ts/pages/api/hello.ts +24 -0
- package/templates/next/wrangler.toml +57 -0
- package/templates/nuxt/c3.ts +91 -18
- package/templates/nuxt/templates/env.d.ts +14 -0
- package/templates/nuxt/templates/worker-configuration.d.ts +3 -0
- package/templates/nuxt/templates/wrangler.toml +50 -0
- package/templates/queues/c3.ts +7 -5
- package/templates/qwik/c3.ts +76 -23
- package/templates/qwik/snippets/getPlatformProxy.ts +6 -0
- package/templates/qwik/templates/worker-configuration.d.ts +3 -0
- package/templates/qwik/templates/wrangler.toml +50 -0
- package/templates/remix/c3.ts +37 -3
- package/templates/remix/templates/worker-configuration.d.ts +3 -0
- package/templates/remix/templates/wrangler.toml +50 -0
- package/templates/scheduled/c3.ts +7 -5
- package/templates/solid/c3.ts +54 -10
- package/templates/svelte/c3.ts +80 -28
- package/templates/svelte/js/src/hooks.server.js +25 -0
- package/templates/svelte/js/wrangler.toml +50 -0
- package/templates/svelte/ts/src/hooks.server.ts +24 -0
- package/templates/svelte/ts/wrangler.toml +50 -0
- package/templates/next/templates.ts +0 -281
- package/templates/solid/js/vite.config.js +0 -12
- package/templates/solid/ts/vite.config.ts +0 -12
- package/templates/svelte/templates.ts +0 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "create-cloudflare",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-96e4e165",
|
|
4
4
|
"description": "A CLI for creating and deploying new applications to Cloudflare.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cloudflare",
|
|
@@ -50,6 +50,7 @@
|
|
|
50
50
|
"deepmerge": "^4.3.1",
|
|
51
51
|
"degit": "^2.8.4",
|
|
52
52
|
"dns2": "^2.1.0",
|
|
53
|
+
"dotenv": "^16.0.0",
|
|
53
54
|
"esbuild": "^0.17.12",
|
|
54
55
|
"execa": "^7.1.1",
|
|
55
56
|
"glob": "^10.3.3",
|
|
@@ -60,14 +61,14 @@
|
|
|
60
61
|
"recast": "^0.22.0",
|
|
61
62
|
"semver": "^7.5.1",
|
|
62
63
|
"typescript": "^5.0.2",
|
|
63
|
-
"undici": "5.28.
|
|
64
|
+
"undici": "5.28.3",
|
|
64
65
|
"vite-tsconfig-paths": "^4.0.8",
|
|
65
66
|
"which-pm-runs": "^1.1.0",
|
|
66
67
|
"yargs": "^17.7.1",
|
|
67
68
|
"yarn": "^1.22.19",
|
|
68
|
-
"@cloudflare/
|
|
69
|
-
"wrangler": "3.
|
|
70
|
-
"@cloudflare/
|
|
69
|
+
"@cloudflare/workers-tsconfig": "0.0.0",
|
|
70
|
+
"wrangler": "3.32.0",
|
|
71
|
+
"@cloudflare/cli": "1.1.1"
|
|
71
72
|
},
|
|
72
73
|
"engines": {
|
|
73
74
|
"node": ">=18.14.1"
|
|
@@ -77,6 +78,7 @@
|
|
|
77
78
|
},
|
|
78
79
|
"scripts": {
|
|
79
80
|
"build": "node -r esbuild-register scripts/build.ts",
|
|
81
|
+
"dev:codemod": "node -r esbuild-register scripts/codemodDev.ts",
|
|
80
82
|
"check:lint": "eslint .",
|
|
81
83
|
"check:type": "tsc",
|
|
82
84
|
"lint": "eslint",
|
package/templates/astro/c3.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import { logRaw } from "@cloudflare/cli";
|
|
2
|
-
import { brandColor, dim } from "@cloudflare/cli/colors";
|
|
1
|
+
import { logRaw, updateStatus } from "@cloudflare/cli";
|
|
2
|
+
import { blue, brandColor, dim } from "@cloudflare/cli/colors";
|
|
3
|
+
import { loadTemplateSnippets, transformFile } from "helpers/codemod";
|
|
3
4
|
import { runCommand, runFrameworkGenerator } from "helpers/command";
|
|
4
|
-
import {
|
|
5
|
+
import { usesTypescript } from "helpers/files";
|
|
5
6
|
import { detectPackageManager } from "helpers/packages";
|
|
7
|
+
import * as recast from "recast";
|
|
6
8
|
import type { TemplateConfig } from "../../src/templates";
|
|
7
|
-
import type { C3Context } from "types";
|
|
9
|
+
import type { C3Context, PackageJson } from "types";
|
|
8
10
|
|
|
9
11
|
const { npx } = detectPackageManager();
|
|
10
12
|
|
|
@@ -14,7 +16,7 @@ const generate = async (ctx: C3Context) => {
|
|
|
14
16
|
logRaw(""); // newline
|
|
15
17
|
};
|
|
16
18
|
|
|
17
|
-
const configure = async () => {
|
|
19
|
+
const configure = async (ctx: C3Context) => {
|
|
18
20
|
await runCommand([npx, "astro", "add", "cloudflare", "-y"], {
|
|
19
21
|
silent: true,
|
|
20
22
|
startText: "Installing adapter",
|
|
@@ -22,6 +24,67 @@ const configure = async () => {
|
|
|
22
24
|
`via \`${npx} astro add cloudflare\``
|
|
23
25
|
)}`,
|
|
24
26
|
});
|
|
27
|
+
|
|
28
|
+
updateAstroConfig();
|
|
29
|
+
updateEnvDeclaration(ctx);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const updateAstroConfig = () => {
|
|
33
|
+
const filePath = "astro.config.mjs";
|
|
34
|
+
|
|
35
|
+
updateStatus(`Updating configuration in ${blue(filePath)}`);
|
|
36
|
+
|
|
37
|
+
transformFile(filePath, {
|
|
38
|
+
visitCallExpression: function (n) {
|
|
39
|
+
const callee = n.node.callee as recast.types.namedTypes.Identifier;
|
|
40
|
+
if (callee.name !== "cloudflare") {
|
|
41
|
+
return this.traverse(n);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const b = recast.types.builders;
|
|
45
|
+
n.node.arguments = [
|
|
46
|
+
b.objectExpression([
|
|
47
|
+
b.objectProperty(
|
|
48
|
+
b.identifier("runtime"),
|
|
49
|
+
b.objectExpression([
|
|
50
|
+
b.objectProperty(b.identifier("mode"), b.stringLiteral("local")),
|
|
51
|
+
])
|
|
52
|
+
),
|
|
53
|
+
]),
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
return false;
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const updateEnvDeclaration = (ctx: C3Context) => {
|
|
62
|
+
if (!usesTypescript(ctx)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const filePath = "src/env.d.ts";
|
|
67
|
+
|
|
68
|
+
updateStatus(`Adding type declarations in ${blue(filePath)}`);
|
|
69
|
+
|
|
70
|
+
transformFile(filePath, {
|
|
71
|
+
visitProgram: function (n) {
|
|
72
|
+
const snippets = loadTemplateSnippets(ctx);
|
|
73
|
+
const patch = snippets.runtimeDeclarationTs;
|
|
74
|
+
const b = recast.types.builders;
|
|
75
|
+
|
|
76
|
+
// Preserve comments with the new body
|
|
77
|
+
const comments = n.get("comments").value;
|
|
78
|
+
n.node.comments = comments.map((c: recast.types.namedTypes.CommentLine) =>
|
|
79
|
+
b.commentLine(c.value)
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// Add the patch
|
|
83
|
+
n.get("body").push(...patch);
|
|
84
|
+
|
|
85
|
+
return false;
|
|
86
|
+
},
|
|
87
|
+
});
|
|
25
88
|
};
|
|
26
89
|
|
|
27
90
|
const config: TemplateConfig = {
|
|
@@ -29,12 +92,19 @@ const config: TemplateConfig = {
|
|
|
29
92
|
id: "astro",
|
|
30
93
|
platform: "pages",
|
|
31
94
|
displayName: "Astro",
|
|
95
|
+
copyFiles: {
|
|
96
|
+
path: "./templates",
|
|
97
|
+
},
|
|
98
|
+
devScript: "dev",
|
|
99
|
+
deployScript: "deploy",
|
|
100
|
+
previewScript: "preview",
|
|
32
101
|
generate,
|
|
33
102
|
configure,
|
|
34
|
-
transformPackageJson: async () => ({
|
|
103
|
+
transformPackageJson: async (pkgJson: PackageJson, ctx: C3Context) => ({
|
|
35
104
|
scripts: {
|
|
36
|
-
|
|
37
|
-
|
|
105
|
+
deploy: `astro build && wrangler pages deploy ./dist`,
|
|
106
|
+
preview: `astro build && wrangler pages dev ./dist`,
|
|
107
|
+
...(usesTypescript(ctx) && { "build-cf-types": `wrangler types` }),
|
|
38
108
|
},
|
|
39
109
|
}),
|
|
40
110
|
testFlags: [
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
name = "<TBD>"
|
|
2
|
+
compatibility_date = "<TBD>"
|
|
3
|
+
|
|
4
|
+
# Variable bindings. These are arbitrary, plaintext strings (similar to environment variables)
|
|
5
|
+
# Note: Use secrets to store sensitive data.
|
|
6
|
+
# Docs: https://developers.cloudflare.com/workers/platform/environment-variables
|
|
7
|
+
# [vars]
|
|
8
|
+
# MY_VARIABLE = "production_value"
|
|
9
|
+
|
|
10
|
+
# Bind a KV Namespace. Use KV as persistent storage for small key-value pairs.
|
|
11
|
+
# Docs: https://developers.cloudflare.com/workers/runtime-apis/kv
|
|
12
|
+
# [[kv_namespaces]]
|
|
13
|
+
# binding = "MY_KV_NAMESPACE"
|
|
14
|
+
# id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
15
|
+
|
|
16
|
+
# Bind an R2 Bucket. Use R2 to store arbitrarily large blobs of data, such as files.
|
|
17
|
+
# Docs: https://developers.cloudflare.com/r2/api/workers/workers-api-usage/
|
|
18
|
+
# [[r2_buckets]]
|
|
19
|
+
# binding = "MY_BUCKET"
|
|
20
|
+
# bucket_name = "my-bucket"
|
|
21
|
+
|
|
22
|
+
# Bind a Queue producer. Use this binding to schedule an arbitrary task that may be processed later by a Queue consumer.
|
|
23
|
+
# Docs: https://developers.cloudflare.com/queues/get-started
|
|
24
|
+
# [[queues.producers]]
|
|
25
|
+
# binding = "MY_QUEUE"
|
|
26
|
+
# queue = "my-queue"
|
|
27
|
+
|
|
28
|
+
# Bind a Queue consumer. Queue Consumers can retrieve tasks scheduled by Producers to act on them.
|
|
29
|
+
# Docs: https://developers.cloudflare.com/queues/get-started
|
|
30
|
+
# [[queues.consumers]]
|
|
31
|
+
# queue = "my-queue"
|
|
32
|
+
|
|
33
|
+
# Bind another Worker service. Use this binding to call another Worker without network overhead.
|
|
34
|
+
# Docs: https://developers.cloudflare.com/workers/platform/services
|
|
35
|
+
# [[services]]
|
|
36
|
+
# binding = "MY_SERVICE"
|
|
37
|
+
# service = "my-service"
|
|
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"]
|
package/templates/common/c3.ts
CHANGED
|
@@ -4,11 +4,13 @@ export default {
|
|
|
4
4
|
displayName: "Example router & proxy Worker",
|
|
5
5
|
platform: "workers",
|
|
6
6
|
copyFiles: {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
variants: {
|
|
8
|
+
js: {
|
|
9
|
+
path: "./js",
|
|
10
|
+
},
|
|
11
|
+
ts: {
|
|
12
|
+
path: "./ts",
|
|
13
|
+
},
|
|
12
14
|
},
|
|
13
15
|
},
|
|
14
16
|
};
|
|
@@ -4,11 +4,13 @@ export default {
|
|
|
4
4
|
displayName: '"Hello World" Durable Object',
|
|
5
5
|
platform: "workers",
|
|
6
6
|
copyFiles: {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
variants: {
|
|
8
|
+
js: {
|
|
9
|
+
path: "./js",
|
|
10
|
+
},
|
|
11
|
+
ts: {
|
|
12
|
+
path: "./ts",
|
|
13
|
+
},
|
|
12
14
|
},
|
|
13
15
|
},
|
|
14
16
|
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`c3`](https://developers.cloudflare.com/pages/get-started/c3).
|
|
2
|
+
|
|
3
|
+
## Getting Started
|
|
4
|
+
|
|
5
|
+
First, run the development server:
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm run dev
|
|
9
|
+
# or
|
|
10
|
+
yarn dev
|
|
11
|
+
# or
|
|
12
|
+
pnpm dev
|
|
13
|
+
# or
|
|
14
|
+
bun dev
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
|
18
|
+
|
|
19
|
+
## Cloudflare integration
|
|
20
|
+
|
|
21
|
+
Besides the `dev` script mentioned above `c3` has added a few extra scripts that allow you to integrate the application with the [Cloudflare Pages](https://pages.cloudflare.com/) environment, these are:
|
|
22
|
+
- `pages:build` to build the application for Pages using the [`@cloudflare/next-on-pages`](https://github.com/cloudflare/next-on-pages) CLI
|
|
23
|
+
- `preview` to locally preview your Pages application using the [Wrangler](https://developers.cloudflare.com/workers/wrangler/) CLI
|
|
24
|
+
- `deploy` to deploy your Pages application using the [Wrangler](https://developers.cloudflare.com/workers/wrangler/) CLI
|
|
25
|
+
|
|
26
|
+
> __Note:__ while the `dev` script is optimal for local development you should preview your Pages application as well (periodically or before deployments) in order to make sure that it can properly work in the Pages environment (for more details see the [`@cloudflare/next-on-pages` recommended workflow](https://github.com/cloudflare/next-on-pages/blob/05b6256/internal-packages/next-dev/README.md#recommended-workflow))
|
|
27
|
+
|
|
28
|
+
### Bindings
|
|
29
|
+
|
|
30
|
+
Cloudflare [Bindings](https://developers.cloudflare.com/pages/functions/bindings/) are what allows you to interact with resources available in the Cloudflare Platform.
|
|
31
|
+
|
|
32
|
+
You can use bindings during development, when previewing locally your application and of course in the deployed application:
|
|
33
|
+
|
|
34
|
+
- To use bindings in dev mode you need to define them in the `next.config.js` file under `setupDevBindings`, this mode uses the `next-dev` `@cloudflare/next-on-pages` submodule. For more details see its [documentation](https://github.com/cloudflare/next-on-pages/blob/05b6256/internal-packages/next-dev/README.md).
|
|
35
|
+
|
|
36
|
+
- To use bindings in the preview mode you need to add them to the `pages:preview` script accordingly to the `wrangler pages dev` command. For more details see its [documentation](https://developers.cloudflare.com/workers/wrangler/commands/#dev-1) or the [Pages Bindings documentation](https://developers.cloudflare.com/pages/functions/bindings/).
|
|
37
|
+
|
|
38
|
+
- To use bindings in the deployed application you will need to configure them in the Cloudflare [dashboard](https://dash.cloudflare.com/). For more details see the [Pages Bindings documentation](https://developers.cloudflare.com/pages/functions/bindings/).
|
|
39
|
+
|
|
40
|
+
#### KV Example
|
|
41
|
+
|
|
42
|
+
`c3` has added for you an example showing how you can use a KV binding.
|
|
43
|
+
|
|
44
|
+
In order to enable the example:
|
|
45
|
+
- Search for javascript/typescript lines containing the following comment:
|
|
46
|
+
```ts
|
|
47
|
+
// KV Example:
|
|
48
|
+
```
|
|
49
|
+
and uncomment the commented lines below it.
|
|
50
|
+
- Do the same in the `wrangler.toml` file, where
|
|
51
|
+
the comment is:
|
|
52
|
+
```
|
|
53
|
+
# KV Example:
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
After doing this you can run the `dev` or `preview` script and visit the `/api/hello` route to see the example in action.
|
|
57
|
+
|
|
58
|
+
Finally, if you also want to see the example work in the deployed application make sure to add a `MY_KV` 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.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { getRequestContext } from '@cloudflare/next-on-pages'
|
|
2
|
+
|
|
3
|
+
export const runtime = 'edge'
|
|
4
|
+
|
|
5
|
+
export async function GET(request) {
|
|
6
|
+
let responseText = 'Hello World'
|
|
7
|
+
|
|
8
|
+
// In the edge runtime you can use Bindings that are available in your application
|
|
9
|
+
// (for more details see:
|
|
10
|
+
// - https://developers.cloudflare.com/pages/framework-guides/deploy-a-nextjs-site/#use-bindings-in-your-nextjs-application
|
|
11
|
+
// - https://developers.cloudflare.com/pages/functions/bindings/
|
|
12
|
+
// )
|
|
13
|
+
//
|
|
14
|
+
// KV Example:
|
|
15
|
+
// const myKv = getRequestContext().env.MY_KV
|
|
16
|
+
// await myKv.put('suffix', ' from a KV store!')
|
|
17
|
+
// const suffix = await myKv.get('suffix')
|
|
18
|
+
// responseText += suffix
|
|
19
|
+
|
|
20
|
+
return new Response(responseText)
|
|
21
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const runtime = "edge";
|
|
2
|
+
|
|
3
|
+
export default function NotFound() {
|
|
4
|
+
return (
|
|
5
|
+
<>
|
|
6
|
+
<title>404: This page could not be found.</title>
|
|
7
|
+
<div style={styles.error}>
|
|
8
|
+
<div>
|
|
9
|
+
<style
|
|
10
|
+
dangerouslySetInnerHTML={{
|
|
11
|
+
__html: `body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}`,
|
|
12
|
+
}}
|
|
13
|
+
/>
|
|
14
|
+
<h1 className="next-error-h1" style={styles.h1}>
|
|
15
|
+
404
|
|
16
|
+
</h1>
|
|
17
|
+
<div style={styles.desc}>
|
|
18
|
+
<h2 style={styles.h2}>This page could not be found.</h2>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
</>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const styles = {
|
|
27
|
+
error: {
|
|
28
|
+
fontFamily:
|
|
29
|
+
'system-ui,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"',
|
|
30
|
+
height: "100vh",
|
|
31
|
+
textAlign: "center",
|
|
32
|
+
display: "flex",
|
|
33
|
+
flexDirection: "column",
|
|
34
|
+
alignItems: "center",
|
|
35
|
+
justifyContent: "center",
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
desc: {
|
|
39
|
+
display: "inline-block",
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
h1: {
|
|
43
|
+
display: "inline-block",
|
|
44
|
+
margin: "0 20px 0 0",
|
|
45
|
+
padding: "0 23px 0 0",
|
|
46
|
+
fontSize: 24,
|
|
47
|
+
fontWeight: 500,
|
|
48
|
+
verticalAlign: "top",
|
|
49
|
+
lineHeight: "49px",
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
h2: {
|
|
53
|
+
fontSize: 14,
|
|
54
|
+
fontWeight: 400,
|
|
55
|
+
lineHeight: "49px",
|
|
56
|
+
margin: 0,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { NextRequest } from 'next/server'
|
|
2
|
+
import { getRequestContext } from '@cloudflare/next-on-pages'
|
|
3
|
+
|
|
4
|
+
export const runtime = 'edge'
|
|
5
|
+
|
|
6
|
+
export async function GET(request: NextRequest) {
|
|
7
|
+
let responseText = 'Hello World'
|
|
8
|
+
|
|
9
|
+
// In the edge runtime you can use Bindings that are available in your application
|
|
10
|
+
// (for more details see:
|
|
11
|
+
// - https://developers.cloudflare.com/pages/framework-guides/deploy-a-nextjs-site/#use-bindings-in-your-nextjs-application
|
|
12
|
+
// - https://developers.cloudflare.com/pages/functions/bindings/
|
|
13
|
+
// )
|
|
14
|
+
//
|
|
15
|
+
// KV Example:
|
|
16
|
+
// const myKv = getRequestContext().env.MY_KV
|
|
17
|
+
// await myKv.put('suffix', ' from a KV store!')
|
|
18
|
+
// const suffix = await myKv.get('suffix')
|
|
19
|
+
// responseText += suffix
|
|
20
|
+
|
|
21
|
+
return new Response(responseText)
|
|
22
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export const runtime = "edge";
|
|
2
|
+
|
|
3
|
+
export default function NotFound() {
|
|
4
|
+
return (
|
|
5
|
+
<>
|
|
6
|
+
<title>404: This page could not be found.</title>
|
|
7
|
+
<div style={styles.error}>
|
|
8
|
+
<div>
|
|
9
|
+
<style
|
|
10
|
+
dangerouslySetInnerHTML={{
|
|
11
|
+
__html: `body{color:#000;background:#fff;margin:0}.next-error-h1{border-right:1px solid rgba(0,0,0,.3)}@media (prefers-color-scheme:dark){body{color:#fff;background:#000}.next-error-h1{border-right:1px solid rgba(255,255,255,.3)}}`,
|
|
12
|
+
}}
|
|
13
|
+
/>
|
|
14
|
+
<h1 className="next-error-h1" style={styles.h1}>
|
|
15
|
+
404
|
|
16
|
+
</h1>
|
|
17
|
+
<div style={styles.desc}>
|
|
18
|
+
<h2 style={styles.h2}>This page could not be found.</h2>
|
|
19
|
+
</div>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
</>
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const styles = {
|
|
27
|
+
error: {
|
|
28
|
+
fontFamily:
|
|
29
|
+
'system-ui,"Segoe UI",Roboto,Helvetica,Arial,sans-serif,"Apple Color Emoji","Segoe UI Emoji"',
|
|
30
|
+
height: "100vh",
|
|
31
|
+
textAlign: "center",
|
|
32
|
+
display: "flex",
|
|
33
|
+
flexDirection: "column",
|
|
34
|
+
alignItems: "center",
|
|
35
|
+
justifyContent: "center",
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
desc: {
|
|
39
|
+
display: "inline-block",
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
h1: {
|
|
43
|
+
display: "inline-block",
|
|
44
|
+
margin: "0 20px 0 0",
|
|
45
|
+
padding: "0 23px 0 0",
|
|
46
|
+
fontSize: 24,
|
|
47
|
+
fontWeight: 500,
|
|
48
|
+
verticalAlign: "top",
|
|
49
|
+
lineHeight: "49px",
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
h2: {
|
|
53
|
+
fontSize: 14,
|
|
54
|
+
fontWeight: 400,
|
|
55
|
+
lineHeight: "49px",
|
|
56
|
+
margin: 0,
|
|
57
|
+
},
|
|
58
|
+
} as const;
|