Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5268738

Browse files
playground14 and playground15
1 parent 1cc62a6 commit 5268738

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+485
-137
lines changed

examples/common/apps.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ const apps = [
33
// examples
44
"create-next-app",
55
"middleware",
6-
"playground",
6+
"playground14",
7+
"playground15",
78
"vercel-blog-starter",
89
"vercel-commerce",
910
"ssg-app",

examples/instrumentation-app/app/layout.tsx

Lines changed: 0 additions & 7 deletions
This file was deleted.

examples/instrumentation-app/app/page.jsx

Lines changed: 0 additions & 20 deletions
This file was deleted.

examples/instrumentation-app/e2e/playwright.config.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.

examples/instrumentation-app/next.config.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

examples/instrumentation-app/wrangler.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

examples/playground/e2e/playwright.config.ts

Lines changed: 0 additions & 3 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.

examples/instrumentation-app/e2e/instrumentation.spec.ts renamed to examples/playground14/e2e/instrumentation.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ import { describe } from "node:test";
33

44
test.describe("instrumentation", () => {
55
test("the instrumentation register hook should work for the nodejs runtime", async ({ page }) => {
6-
const res = await page.request.get("/api/hello");
6+
const res = await page.request.get("/api/instrumentation");
77
const respJson: Record<string, string> = await res.json();
88
expect(respJson["nodejs-instrumentation-setup"]).toEqual(
99
"this value has been set by calling the instrumentation `register` callback in the nodejs runtime"
1010
);
1111
});
1212

1313
test("the instrumentation register hook should work for the edge runtime", async ({ page }) => {
14-
const res = await page.request.get("/middleware");
14+
const res = await page.request.get("/middleware-instrumentation");
1515
const respJson: Record<string, string> = await res.json();
1616
expect(respJson["edge-instrumentation-setup"]).toEqual(
1717
"this value has been set by calling the instrumentation `register` callback in the edge runtime"
@@ -22,13 +22,13 @@ test.describe("instrumentation", () => {
2222
// (see: https://github.com/opennextjs/opennextjs-cloudflare/issues/408)
2323
describe.skip("isolation", () => {
2424
test("the instrumentation register hook nodejs logic should not effect edge routes", async ({ page }) => {
25-
const res = await page.request.get("/middleware");
25+
const res = await page.request.get("/middleware-instrumentation");
2626
const respJson: Record<string, string> = await res.json();
2727
expect(respJson["nodejs-instrumentation-setup"]).toEqual("undefined");
2828
});
2929

3030
test("the instrumentation register hook edge logic should not effect nodejs routes", async ({ page }) => {
31-
const res = await page.request.get("/api/hello");
31+
const res = await page.request.get("/api/instrumentation");
3232
const respJson: Record<string, string> = await res.json();
3333
expect(respJson["edge-instrumentation-setup"]).toEqual("undefined");
3434
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import { configurePlaywright } from "../../common/config-e2e";
2+
3+
export default configurePlaywright("playground14", { isCI: !!process.env.CI });
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { configurePlaywright } from "../../common/config-e2e";
22

3-
export default configurePlaywright("playground", {
3+
export default configurePlaywright("playground14", {
44
isCI: !!process.env.CI,
55
isWorker: false,
66
});

examples/instrumentation-app/middleware.js renamed to examples/playground14/middleware.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ export function middleware() {
88
}
99

1010
export const config = {
11-
matcher: ["/middleware"],
11+
matcher: ["/middleware-instrumentation"],
1212
};

examples/playground14/next.config.mjs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { initOpenNextCloudflareForDev } from "@opennextjs/cloudflare";
2+
3+
initOpenNextCloudflareForDev();
4+
5+
/** @type {import('next').NextConfig} */
6+
const nextConfig = {
7+
experimental: {
8+
// Generate source map to validate the fix for opennextjs/opennextjs-cloudflare#341
9+
serverSourceMaps: true,
10+
instrumentationHook: true,
11+
},
12+
};
13+
14+
export default nextConfig;

examples/playground/package.json renamed to examples/playground14/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "playground",
2+
"name": "playground14",
33
"version": "0.1.0",
44
"private": true,
55
"type": "module",

examples/playground15/.dev.vars

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NEXTJS_ENV=development
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
TEST_ENV_VAR=TEST_VALUE

examples/instrumentation-app/.gitignore renamed to examples/playground15/.gitignore

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
# dependencies
44
/node_modules
55
/.pnp
6-
.pnp.*
7-
.yarn/*
8-
!.yarn/patches
9-
!.yarn/plugins
10-
!.yarn/releases
11-
!.yarn/versions
6+
.pnp.js
7+
.yarn/install-state.gz
128

139
# testing
1410
/coverage
@@ -28,10 +24,9 @@
2824
npm-debug.log*
2925
yarn-debug.log*
3026
yarn-error.log*
31-
.pnpm-debug.log*
3227

33-
# env files (can opt-in for committing if needed)
34-
.env*
28+
# local env files
29+
.env*.local
3530

3631
# vercel
3732
.vercel
@@ -40,6 +35,9 @@ yarn-error.log*
4035
*.tsbuildinfo
4136
next-env.d.ts
4237

38+
# wrangler
39+
.wrangler
40+
4341
# playwright
4442
/test-results/
4543
/playwright-report/

examples/playground15/README.md

Lines changed: 1 addition & 0 deletions
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Use headers to force a dynamic response
2+
import { headers } from "next/headers";
3+
4+
export async function GET() {
5+
const nextConfig = process.env.__NEXT_PRIVATE_STANDALONE_CONFIG
6+
? JSON.parse(process.env.__NEXT_PRIVATE_STANDALONE_CONFIG)
7+
: undefined;
8+
return Response.json({ nextConfig, headers: headers() });
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
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+
6+
export async function GET() {
7+
return new Response(JSON.stringify(process.env));
8+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { headers } from "next/headers";
2+
3+
import { getCloudflareContext } from "@opennextjs/cloudflare";
4+
5+
export async function GET() {
6+
const headersList = await headers();
7+
8+
const fromCloudflareContext = headersList.has("from-cloudflare-context");
9+
10+
if (!fromCloudflareContext) {
11+
return new Response("Hello World!");
12+
}
13+
14+
// Retrieve the bindings defined in wrangler.json
15+
return new Response(getCloudflareContext().env.hello);
16+
}
17+
18+
export async function POST(request: Request) {
19+
const text = await request.text();
20+
return new Response(`Hello post-World! body=${text}`);
21+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NextResponse } from "next/server";
2+
3+
export function GET() {
4+
return NextResponse.json({
5+
"nodejs-instrumentation-setup": globalThis["__NODEJS_INSTRUMENTATION_SETUP"] ?? "undefined",
6+
"edge-instrumentation-setup": globalThis["__EDGE_INSTRUMENTATION_SETUP"] ?? "undefined",
7+
});
8+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { NextRequest } from "next/server";
2+
3+
export const GET = (request: NextRequest) => {
4+
return new Response(JSON.stringify({ nextUrl: request.nextUrl.href, url: request.url }));
5+
};
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
}

examples/playground15/app/layout.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export const metadata = {
2+
title: "API hello-world",
3+
description: "a simple api hello-world app",
4+
};
5+
6+
export default function RootLayout({ children }) {
7+
return (
8+
<html lang="en">
9+
<body>{children}</body>
10+
</html>
11+
);
12+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { ImageResponse } from "next/og";
2+
3+
export const dynamic = "force-dynamic";
4+
5+
export async function GET() {
6+
try {
7+
return new ImageResponse(
8+
(
9+
<div
10+
style={{
11+
backgroundColor: "black",
12+
backgroundSize: "150px 150px",
13+
height: "100%",
14+
width: "100%",
15+
display: "flex",
16+
textAlign: "center",
17+
alignItems: "center",
18+
justifyContent: "center",
19+
flexDirection: "column",
20+
flexWrap: "nowrap",
21+
}}
22+
>
23+
<div
24+
style={{
25+
display: "flex",
26+
alignItems: "center",
27+
justifyContent: "center",
28+
justifyItems: "center",
29+
}}
30+
>
31+
<img
32+
alt="Vercel"
33+
height={200}
34+
src="data:image/svg+xml,%3Csvg width='116' height='100' fill='white' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M57.5 0L115 100H0L57.5 0z' /%3E%3C/svg%3E"
35+
style={{ margin: "0 30px" }}
36+
width={232}
37+
/>
38+
</div>
39+
<div
40+
style={{
41+
fontSize: 60,
42+
fontStyle: "normal",
43+
letterSpacing: "-0.025em",
44+
color: "white",
45+
marginTop: 30,
46+
padding: "0 120px",
47+
lineHeight: 1.4,
48+
whiteSpace: "pre-wrap",
49+
}}
50+
>
51+
'next/og'
52+
</div>
53+
</div>
54+
),
55+
{
56+
width: 1200,
57+
height: 630,
58+
}
59+
);
60+
} catch (e: any) {
61+
return new Response("Failed to generate the image", {
62+
status: 500,
63+
});
64+
}
65+
}

examples/playground15/app/page.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
export default function Home() {
2+
return (
3+
<main>
4+
<p>Test misc Next features</p>
5+
</main>
6+
);
7+
}

0 commit comments

Comments
 (0)