File tree Expand file tree Collapse file tree 6 files changed +103
-2
lines changed Expand file tree Collapse file tree 6 files changed +103
-2
lines changed Original file line number Diff line number Diff line change
1
+ // This test relies on using `.dev.vars` to set the environment to `development`
2
+ // However `next build` is not passed an environment, so we do not want to cache
3
+ // the output.
4
+ export const dynamic = "force-dynamic" ;
5
+
1
6
export async function GET ( ) {
2
7
return new Response ( JSON . stringify ( process . env ) ) ;
3
8
}
Original file line number Diff line number Diff line change
1
+ // Imported from https://nextjs.org/docs/app/building-your-application/data-fetching/incremental-static-regeneration
2
+ interface Post {
3
+ id : string ;
4
+ title : string ;
5
+ content : string ;
6
+ }
7
+
8
+ // Next.js will invalidate the cache when a
9
+ // request comes in, at most once every 1 hour.
10
+ export const revalidate = 3600 ;
11
+
12
+ // We'll prerender only the params from `generateStaticParams` at build time.
13
+ // If a request comes in for a path that hasn't been generated,
14
+ // Next.js will server-render the page on-demand.
15
+ export const dynamicParams = true ;
16
+
17
+ export async function generateStaticParams ( ) {
18
+ return [ { id : "1" } , { id : "2" } , { id : "3" } ] ;
19
+ }
20
+
21
+ export default async function Page ( { params } : { params : Promise < { id : string } > } ) {
22
+ const id = ( await params ) . id ;
23
+ const post : Post = await fetch ( `https://api.vercel.app/blog/${ id } ` ) . then ( ( res ) => res . json ( ) ) ;
24
+ return (
25
+ < main >
26
+ < h1 > { post . title } </ h1 >
27
+ < p > { post . content } </ p >
28
+ </ main >
29
+ ) ;
30
+ }
Original file line number Diff line number Diff line change
1
+ // Imported from https://nextjs.org/docs/app/building-your-application/data-fetching/incremental-static-regeneration
2
+ interface Post {
3
+ id : string ;
4
+ title : string ;
5
+ content : string ;
6
+ }
7
+
8
+ // Next.js will invalidate the cache when a
9
+ // request comes in, at most once every 1 hour.
10
+ export const revalidate = 3600 ;
11
+
12
+ // We'll prerender only the params from `generateStaticParams` at build time.
13
+ // If a request comes in for a path that hasn't been generated, it will 404.
14
+ export const dynamicParams = false ;
15
+
16
+ export async function generateStaticParams ( ) {
17
+ return [ { id : "1" } , { id : "2" } , { id : "3" } ] ;
18
+ }
19
+
20
+ export default async function Page ( { params } : { params : Promise < { id : string } > } ) {
21
+ const id = ( await params ) . id ;
22
+ const post : Post = await fetch ( `https://api.vercel.app/blog/${ id } ` ) . then ( ( res ) => res . json ( ) ) ;
23
+ return (
24
+ < main >
25
+ < h1 > { post . title } </ h1 >
26
+ < p > { post . content } </ p >
27
+ </ main >
28
+ ) ;
29
+ }
Original file line number Diff line number Diff line change
1
+ import { test , expect , type APIResponse } from "@playwright/test" ;
2
+ import type { BinaryLike } from "node:crypto" ;
3
+ import { createHash } from "node:crypto" ;
4
+
5
+ test ( "Generated pages exist" , async ( { page } ) => {
6
+ const generatedIds = [ 1 , 2 , 3 ] ;
7
+ let res : APIResponse ;
8
+ for ( const id of generatedIds ) {
9
+ res = await page . request . get ( `/isr/${ id } /dynamic` ) ;
10
+ expect ( res . status ( ) ) . toBe ( 200 ) ;
11
+ res = await page . request . get ( `/isr/${ id } /no-dynamic` ) ;
12
+ expect ( res . status ( ) ) . toBe ( 200 ) ;
13
+ }
14
+ } ) ;
15
+
16
+ test ( "Non generated pages 404 when dynamic is false" , async ( { page } ) => {
17
+ const generatedIds = [ 4 , 5 , 6 ] ;
18
+ for ( const id of generatedIds ) {
19
+ const res = await page . request . get ( `/isr/${ id } /no-dynamic` ) ;
20
+ expect ( res . status ( ) ) . toBe ( 404 ) ;
21
+ }
22
+ } ) ;
23
+
24
+ test ( "Non generated pages are generated when dynamic is true" , async ( { page } ) => {
25
+ const generatedIds = [ 4 , 5 , 6 ] ;
26
+ for ( const id of generatedIds ) {
27
+ const res = await page . request . get ( `/isr/${ id } /dynamic` ) ;
28
+ expect ( res . status ( ) ) . toBe ( 200 ) ;
29
+ }
30
+ } ) ;
Original file line number Diff line number Diff line change 1
1
import type { OpenNextConfig } from "@opennextjs/aws/types/open-next.js" ;
2
+ import cache from "@opennextjs/cloudflare/kv-cache" ;
2
3
3
4
const config : OpenNextConfig = {
4
5
default : {
5
6
override : {
6
7
wrapper : "cloudflare-node" ,
7
8
converter : "edge" ,
9
+ incrementalCache : async ( ) => cache ,
10
+ queue : "direct" ,
8
11
// Unused implementation
9
- incrementalCache : "dummy" ,
10
12
tagCache : "dummy" ,
11
- queue : "dummy" ,
12
13
} ,
13
14
} ,
14
15
Original file line number Diff line number Diff line change 8
8
"directory" : " .open-next/assets" ,
9
9
"binding" : " ASSETS"
10
10
},
11
+ "kv_namespaces" : [
12
+ {
13
+ "binding" : " NEXT_CACHE_WORKERS_KV" ,
14
+ "id" : " <BINDING_ID>"
15
+ }
16
+ ],
11
17
"vars" : {
12
18
"hello" : " Hello World from the cloudflare context!"
13
19
}
You can’t perform that action at this time.
0 commit comments