@opennextjs/cloudflare 0.0.0-af15fd1 → 0.0.0-cf5113b
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 +53 -8
- package/dist/api/chunk-VTBEIZPQ.mjs +32 -0
- package/dist/api/get-cloudflare-context.d.mts +0 -2
- package/dist/api/get-cloudflare-context.mjs +1 -1
- package/dist/api/index.mjs +1 -1
- package/dist/cli/cache-handler.mjs +1 -1
- package/dist/cli/index.mjs +393 -309
- package/dist/cli/templates/shims/node-fs.ts +1 -1
- package/dist/cli/templates/worker.ts +19 -13
- package/package.json +13 -2
- package/dist/api/chunk-LA734VUG.mjs +0 -14
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Deploy Next.js apps to Cloudflare!
|
|
4
4
|
|
|
5
|
-
OpenNext for Cloudflare is Cloudflare specific adapter that enables deployment of Next.js applications to Cloudflare.
|
|
5
|
+
[OpenNext for Cloudflare](https://opennext.js.org/cloudflare) is Cloudflare specific adapter that enables deployment of Next.js applications to Cloudflare.
|
|
6
6
|
|
|
7
7
|
## Getting started
|
|
8
8
|
|
|
@@ -13,7 +13,13 @@ You can use [`create-next-app`](https://nextjs.org/docs/pages/api-reference/cli/
|
|
|
13
13
|
- add the following `devDependencies` to the `package.json`:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
+
npm add -D wrangler@latest @opennextjs/cloudflare
|
|
17
|
+
# or
|
|
16
18
|
pnpm add -D wrangler@latest @opennextjs/cloudflare
|
|
19
|
+
# or
|
|
20
|
+
yarn add -D wrangler@latest @opennextjs/cloudflare
|
|
21
|
+
# or
|
|
22
|
+
bun add -D wrangler@latest @opennextjs/cloudflare
|
|
17
23
|
```
|
|
18
24
|
|
|
19
25
|
- add a `wrangler.toml` at the root of your project
|
|
@@ -27,9 +33,34 @@ You can use [`create-next-app`](https://nextjs.org/docs/pages/api-reference/cli/
|
|
|
27
33
|
compatibility_flags = ["nodejs_compat"]
|
|
28
34
|
|
|
29
35
|
# Use the new Workers + Assets to host the static frontend files
|
|
30
|
-
|
|
36
|
+
assets = { directory = ".worker-next/assets", binding = "ASSETS" }
|
|
31
37
|
```
|
|
32
38
|
|
|
39
|
+
You can enable Incremental Static Regeneration ([ISR](https://nextjs.org/docs/app/building-your-application/data-fetching/incremental-static-regeneration)) by adding a KV binding named `NEXT_CACHE_WORKERS_KV` to your `wrangler.toml`:
|
|
40
|
+
|
|
41
|
+
- Create the binding
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx wrangler kv namespace create NEXT_CACHE_WORKERS_KV
|
|
45
|
+
# or
|
|
46
|
+
pnpm wrangler kv namespace create NEXT_CACHE_WORKERS_KV
|
|
47
|
+
# or
|
|
48
|
+
yarn wrangler kv namespace create NEXT_CACHE_WORKERS_KV
|
|
49
|
+
# or
|
|
50
|
+
bun wrangler kv namespace create NEXT_CACHE_WORKERS_KV
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- Paste the snippet to your `wrangler.toml`:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
[[kv_namespaces]]
|
|
57
|
+
binding = "NEXT_CACHE_WORKERS_KV"
|
|
58
|
+
id = "..."
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
> [!WARNING]
|
|
62
|
+
> The current support for ISR is limited.
|
|
63
|
+
|
|
33
64
|
## Local development
|
|
34
65
|
|
|
35
66
|
- you can use the regular `next` CLI to start the Next.js dev server:
|
|
@@ -41,13 +72,25 @@ Run the following commands to preview the production build of your application l
|
|
|
41
72
|
- build the app and adapt it for Cloudflare
|
|
42
73
|
|
|
43
74
|
```bash
|
|
44
|
-
|
|
75
|
+
npx cloudflare
|
|
76
|
+
# or
|
|
77
|
+
pnpm cloudflare
|
|
78
|
+
# or
|
|
79
|
+
yarn cloudflare
|
|
80
|
+
# or
|
|
81
|
+
bun cloudflare
|
|
45
82
|
```
|
|
46
83
|
|
|
47
84
|
- Preview the app in Wrangler
|
|
48
85
|
|
|
49
86
|
```bash
|
|
87
|
+
npx wrangler dev
|
|
88
|
+
# or
|
|
50
89
|
pnpm wrangler dev
|
|
90
|
+
# or
|
|
91
|
+
yarn wrangler dev
|
|
92
|
+
# or
|
|
93
|
+
bun wrangler dev
|
|
51
94
|
```
|
|
52
95
|
|
|
53
96
|
## Deploy your app
|
|
@@ -57,9 +100,11 @@ Deploy your application to production with the following:
|
|
|
57
100
|
- build the app and adapt it for Cloudflare
|
|
58
101
|
|
|
59
102
|
```bash
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
103
|
+
npx cloudflare && npx wrangler deploy
|
|
104
|
+
# or
|
|
105
|
+
pnpm cloudflare && pnpm wrangler deploy
|
|
106
|
+
# or
|
|
107
|
+
yarn cloudflare && yarn wrangler deploy
|
|
108
|
+
# or
|
|
109
|
+
bun cloudflare && bun wrangler deploy
|
|
65
110
|
```
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
// src/api/get-cloudflare-context.ts
|
|
2
|
+
import "server-only";
|
|
3
|
+
var cloudflareContextSymbol = Symbol.for("__cloudflare-context__");
|
|
4
|
+
async function getCloudflareContext() {
|
|
5
|
+
const global = globalThis;
|
|
6
|
+
const cloudflareContext = global[cloudflareContextSymbol];
|
|
7
|
+
if (!cloudflareContext) {
|
|
8
|
+
return getCloudflareContextInNextDev();
|
|
9
|
+
}
|
|
10
|
+
return cloudflareContext;
|
|
11
|
+
}
|
|
12
|
+
var cloudflareContextInNextDevSymbol = Symbol.for("__next-dev/cloudflare-context__");
|
|
13
|
+
async function getCloudflareContextInNextDev() {
|
|
14
|
+
const global = globalThis;
|
|
15
|
+
if (!global[cloudflareContextInNextDevSymbol]) {
|
|
16
|
+
const { getPlatformProxy } = await import(
|
|
17
|
+
/* webpackIgnore: true */
|
|
18
|
+
`${"__wrangler".replaceAll("_", "")}`
|
|
19
|
+
);
|
|
20
|
+
const { env, cf, ctx } = await getPlatformProxy();
|
|
21
|
+
global[cloudflareContextInNextDevSymbol] = {
|
|
22
|
+
env,
|
|
23
|
+
cf,
|
|
24
|
+
ctx
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return global[cloudflareContextInNextDevSymbol];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export {
|
|
31
|
+
getCloudflareContext
|
|
32
|
+
};
|
|
@@ -19,8 +19,6 @@ type CloudflareContext<CfProperties extends Record<string, unknown> = IncomingRe
|
|
|
19
19
|
/**
|
|
20
20
|
* Utility to get the current Cloudflare context
|
|
21
21
|
*
|
|
22
|
-
* Throws an error if the context could not be retrieved
|
|
23
|
-
*
|
|
24
22
|
* @returns the cloudflare context
|
|
25
23
|
*/
|
|
26
24
|
declare function getCloudflareContext<CfProperties extends Record<string, unknown> = IncomingRequestCfProperties, Context = ExecutionContext>(): Promise<CloudflareContext<CfProperties, Context>>;
|
package/dist/api/index.mjs
CHANGED