Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions examples/playground/app/api/env/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// This test relies on using `.dev.vars` to set the environment to `development`
// However `next build` is not passed an environment, so we do not want to cache
// the output.
export const dynamic = "force-dynamic";

export async function GET() {
return new Response(JSON.stringify(process.env));
}
30 changes: 30 additions & 0 deletions examples/playground/app/isr/[id]/dynamic/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Imported from https://nextjs.org/docs/app/building-your-application/data-fetching/incremental-static-regeneration
interface Post {
id: string;
title: string;
content: string;
}

// Next.js will invalidate the cache when a
// request comes in, at most once every 1 hour.
export const revalidate = 3600;

// We'll prerender only the params from `generateStaticParams` at build time.
// If a request comes in for a path that hasn't been generated,
// Next.js will server-render the page on-demand.
export const dynamicParams = true;

export async function generateStaticParams() {
return [{ id: "1" }, { id: "2" }, { id: "3" }];
}

export default async function Page({ params }: { params: Promise<{ id: string }> }) {
const id = (await params).id;
const post: Post = await fetch(`https://api.vercel.app/blog/${id}`).then((res) => res.json());
return (
<main>
<h1>{post.title}</h1>
<p>{post.content}</p>
</main>
);
}
29 changes: 29 additions & 0 deletions examples/playground/app/isr/[id]/no-dynamic/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Imported from https://nextjs.org/docs/app/building-your-application/data-fetching/incremental-static-regeneration
interface Post {
id: string;
title: string;
content: string;
}

// Next.js will invalidate the cache when a
// request comes in, at most once every 1 hour.
export const revalidate = 3600;

// We'll prerender only the params from `generateStaticParams` at build time.
// If a request comes in for a path that hasn't been generated, it will 404.
export const dynamicParams = false;

export async function generateStaticParams() {
return [{ id: "1" }, { id: "2" }, { id: "3" }];
}

export default async function Page({ params }: { params: Promise<{ id: string }> }) {
const id = (await params).id;
const post: Post = await fetch(`https://api.vercel.app/blog/${id}`).then((res) => res.json());
return (
<main>
<h1>{post.title}</h1>
<p>{post.content}</p>
</main>
);
}
30 changes: 30 additions & 0 deletions examples/playground/e2e/isr.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { test, expect, type APIResponse } from "@playwright/test";
import type { BinaryLike } from "node:crypto";
import { createHash } from "node:crypto";

test("Generated pages exist", async ({ page }) => {
const generatedIds = [1, 2, 3];
let res: APIResponse;
for (const id of generatedIds) {
res = await page.request.get(`/isr/${id}/dynamic`);
expect(res.status()).toBe(200);
res = await page.request.get(`/isr/${id}/no-dynamic`);
expect(res.status()).toBe(200);
}
});

test("Non generated pages 404 when dynamic is false", async ({ page }) => {
const generatedIds = [4, 5, 6];
for (const id of generatedIds) {
const res = await page.request.get(`/isr/${id}/no-dynamic`);
expect(res.status()).toBe(404);
}
});

test("Non generated pages are generated when dynamic is true", async ({ page }) => {
const generatedIds = [4, 5, 6];
for (const id of generatedIds) {
const res = await page.request.get(`/isr/${id}/dynamic`);
expect(res.status()).toBe(200);
}
});
5 changes: 3 additions & 2 deletions examples/playground/open-next.config.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import type { OpenNextConfig } from "@opennextjs/aws/types/open-next.js";
import cache from "@opennextjs/cloudflare/kv-cache";

const config: OpenNextConfig = {
default: {
override: {
wrapper: "cloudflare-node",
converter: "edge",
incrementalCache: async () => cache,
queue: "direct",
// Unused implementation
incrementalCache: "dummy",
tagCache: "dummy",
queue: "dummy",
},
},

Expand Down
6 changes: 6 additions & 0 deletions examples/playground/wrangler.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
"directory": ".open-next/assets",
"binding": "ASSETS"
},
"kv_namespaces": [
{
"binding": "NEXT_CACHE_WORKERS_KV",
"id": "<BINDING_ID>"
}
],
"vars": {
"hello": "Hello World from the cloudflare context!"
}
Expand Down