@opennextjs/cloudflare 0.0.0-9a03245 → 0.0.0-af15fd1
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
CHANGED
|
@@ -30,25 +30,6 @@ You can use [`create-next-app`](https://nextjs.org/docs/pages/api-reference/cli/
|
|
|
30
30
|
experimental_assets = { directory = ".worker-next/assets", binding = "ASSETS" }
|
|
31
31
|
```
|
|
32
32
|
|
|
33
|
-
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`:
|
|
34
|
-
|
|
35
|
-
- Create the binding
|
|
36
|
-
|
|
37
|
-
```bash
|
|
38
|
-
npx wrangler kv namespace create NEXT_CACHE_WORKERS_KV
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
- Paste the snippet to your `wrangler.toml`:
|
|
42
|
-
|
|
43
|
-
```bash
|
|
44
|
-
[[kv_namespaces]]
|
|
45
|
-
binding = "NEXT_CACHE_WORKERS_KV"
|
|
46
|
-
id = "..."
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
> [!WARNING]
|
|
50
|
-
> The current support for ISR is limited.
|
|
51
|
-
|
|
52
33
|
## Local development
|
|
53
34
|
|
|
54
35
|
- you can use the regular `next` CLI to start the Next.js dev server:
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// src/api/get-cloudflare-context.ts
|
|
2
|
+
import "server-only";
|
|
3
|
+
var cloudflareContextSymbol = Symbol.for("__cloudflare-context__");
|
|
4
|
+
async function getCloudflareContext() {
|
|
5
|
+
const cloudflareContext = globalThis[cloudflareContextSymbol];
|
|
6
|
+
if (!cloudflareContext) {
|
|
7
|
+
throw new Error("Cloudflare context is not defined!");
|
|
8
|
+
}
|
|
9
|
+
return cloudflareContext;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
getCloudflareContext
|
|
14
|
+
};
|
|
@@ -19,6 +19,8 @@ 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
|
+
*
|
|
22
24
|
* @returns the cloudflare context
|
|
23
25
|
*/
|
|
24
26
|
declare function getCloudflareContext<CfProperties extends Record<string, unknown> = IncomingRequestCfProperties, Context = ExecutionContext>(): Promise<CloudflareContext<CfProperties, Context>>;
|
package/dist/api/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opennextjs/cloudflare",
|
|
3
3
|
"description": "Cloudflare builder for next apps",
|
|
4
|
-
"version": "0.0.0-
|
|
4
|
+
"version": "0.0.0-af15fd1",
|
|
5
5
|
"bin": "dist/cli/index.mjs",
|
|
6
6
|
"main": "./dist/api/index.mjs",
|
|
7
7
|
"types": "./dist/api/index.d.mts",
|
|
@@ -43,9 +43,6 @@
|
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"ts-morph": "^23.0.0"
|
|
45
45
|
},
|
|
46
|
-
"peerDependencies": {
|
|
47
|
-
"wrangler": "^3.78.6"
|
|
48
|
-
},
|
|
49
46
|
"scripts": {
|
|
50
47
|
"build": "tsup",
|
|
51
48
|
"build:watch": "tsup --watch src",
|
|
@@ -1,32 +0,0 @@
|
|
|
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
|
-
};
|