Skip to content

Commit baf8ff4

Browse files
authored
test(e2e): import app-router from @opennextjs/aws (#274)
1 parent 27ab1ab commit baf8ff4

Some content is hidden

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

74 files changed

+1858
-120
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ node_modules
22
.DS_Store
33

44
output
5-
.worker-next
65
.open-next
76
.wrangler
7+
.turbo
88
dist

examples/e2e/app-router/.gitignore

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
.open-next
14+
/out/
15+
16+
# production
17+
/build
18+
19+
# misc
20+
.DS_Store
21+
*.pem
22+
23+
# debug
24+
npm-debug.log*
25+
yarn-debug.log*
26+
yarn-error.log*
27+
28+
# local env files
29+
.env*.local
30+
31+
# vercel
32+
.vercel
33+
34+
# typescript
35+
*.tsbuildinfo
36+
next-env.d.ts

examples/e2e/app-router/CHANGELOG.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# app-router
2+
3+
## 0.1.4
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [[`9595714ac23e5f131b879d04d5cfb2a5d11bdbdd`](https://github.com/opennextjs/opennextjs-aws/commit/9595714ac23e5f131b879d04d5cfb2a5d11bdbdd), [`4e88b47935523de1d15da067b56105bd6be91e47`](https://github.com/opennextjs/opennextjs-aws/commit/4e88b47935523de1d15da067b56105bd6be91e47), [`7140ca56e1e88d7a7cae327eceb3ef8c2fde2a1e`](https://github.com/opennextjs/opennextjs-aws/commit/7140ca56e1e88d7a7cae327eceb3ef8c2fde2a1e)]:
8+
- @opennextjs/aws@3.3.1
9+
10+
## 0.1.3
11+
12+
### Patch Changes
13+
14+
- Updated dependencies [[`4d328e3fc306b878e9497986baa65bfd1d4de66a`](https://github.com/opennextjs/opennextjs-aws/commit/4d328e3fc306b878e9497986baa65bfd1d4de66a), [`2b2a48b70ae95b5e600ac2e4b7f2df8702c5c26e`](https://github.com/opennextjs/opennextjs-aws/commit/2b2a48b70ae95b5e600ac2e4b7f2df8702c5c26e), [`f685ddea8f8a5c82591dc02713aff7138f2d9896`](https://github.com/opennextjs/opennextjs-aws/commit/f685ddea8f8a5c82591dc02713aff7138f2d9896), [`ef1fe48d570863266c271e5dedaf02b943849ded`](https://github.com/opennextjs/opennextjs-aws/commit/ef1fe48d570863266c271e5dedaf02b943849ded), [`8ab921f8b5bd40c7ba109ccef3e59a6c24283fb2`](https://github.com/opennextjs/opennextjs-aws/commit/8ab921f8b5bd40c7ba109ccef3e59a6c24283fb2), [`2202f36ce0f87357b249bd127cdd5e84d6deffd3`](https://github.com/opennextjs/opennextjs-aws/commit/2202f36ce0f87357b249bd127cdd5e84d6deffd3), [`44392ba82990d43e16a614113d9e7d8e257e5bdd`](https://github.com/opennextjs/opennextjs-aws/commit/44392ba82990d43e16a614113d9e7d8e257e5bdd), [`4dea7ea2f5ffd1848e51502c88d2efcc1896bb8c`](https://github.com/opennextjs/opennextjs-aws/commit/4dea7ea2f5ffd1848e51502c88d2efcc1896bb8c), [`0ac604e5867497cc93fb677b5ebc28ef87e057f8`](https://github.com/opennextjs/opennextjs-aws/commit/0ac604e5867497cc93fb677b5ebc28ef87e057f8), [`1ece6b479bb4e0309892ffbd1200870821a410c4`](https://github.com/opennextjs/opennextjs-aws/commit/1ece6b479bb4e0309892ffbd1200870821a410c4), [`697681bf9ce25212ce4e2e94d886ca425428280d`](https://github.com/opennextjs/opennextjs-aws/commit/697681bf9ce25212ce4e2e94d886ca425428280d)]:
15+
- @opennextjs/aws@3.3.0
16+
17+
## 0.1.2
18+
19+
### Patch Changes
20+
21+
- Updated dependencies [[`6f798debb575b157acb2f5068658f95ace0fae50`](https://github.com/opennextjs/opennextjs-aws/commit/6f798debb575b157acb2f5068658f95ace0fae50), [`fe600ac6f5e513376cf233a5d2ce68affaa3aa5a`](https://github.com/opennextjs/opennextjs-aws/commit/fe600ac6f5e513376cf233a5d2ce68affaa3aa5a), [`5f0cbc8feac9eec728c27bb3b7ff5c3f3bc26716`](https://github.com/opennextjs/opennextjs-aws/commit/5f0cbc8feac9eec728c27bb3b7ff5c3f3bc26716), [`8b51108d9aee7e5ed3027c1ceda99091b579951d`](https://github.com/opennextjs/opennextjs-aws/commit/8b51108d9aee7e5ed3027c1ceda99091b579951d), [`b999c4e9a38499680bed77ddeb94b62a3301c0fa`](https://github.com/opennextjs/opennextjs-aws/commit/b999c4e9a38499680bed77ddeb94b62a3301c0fa), [`ba84259d2e35e79a562a7e3f055e350a03c9d651`](https://github.com/opennextjs/opennextjs-aws/commit/ba84259d2e35e79a562a7e3f055e350a03c9d651)]:
22+
- @opennextjs/aws@3.2.2
23+
24+
## 0.1.1
25+
26+
### Patch Changes
27+
28+
- Updated dependencies [[`cf33973f3fbab73e77898fdd072a00a1f037257a`](https://github.com/opennextjs/opennextjs-aws/commit/cf33973f3fbab73e77898fdd072a00a1f037257a), [`77d87e7a870fad6afad022bf75aca18c8656c268`](https://github.com/opennextjs/opennextjs-aws/commit/77d87e7a870fad6afad022bf75aca18c8656c268), [`a43b82b4cb68889371ac8260aefef9e04eefb037`](https://github.com/opennextjs/opennextjs-aws/commit/a43b82b4cb68889371ac8260aefef9e04eefb037), [`bfa1a8c4056bd691fb57617dd6287693e51071b4`](https://github.com/opennextjs/opennextjs-aws/commit/bfa1a8c4056bd691fb57617dd6287693e51071b4), [`5839217411012d1df2874d299daa977ba3701c2c`](https://github.com/opennextjs/opennextjs-aws/commit/5839217411012d1df2874d299daa977ba3701c2c), [`dfc174d88b7bcc54eede09c98d9443dd84b93fd8`](https://github.com/opennextjs/opennextjs-aws/commit/dfc174d88b7bcc54eede09c98d9443dd84b93fd8)]:
29+
- @opennextjs/aws@3.2.1

examples/e2e/app-router/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# App Router
2+
3+
This project uses the App Router exclusively...
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { getSong } from "@example/shared/api";
2+
import Modal from "@example/shared/components/Modal";
3+
4+
type Props = {
5+
params: Promise<{
6+
album: string;
7+
song: string;
8+
}>;
9+
};
10+
export default async function SongPage(props: Props) {
11+
const params = await props.params;
12+
const song = await getSong(params.album, params.song);
13+
return (
14+
<Modal>
15+
<h1>Modal</h1>
16+
Album: {decodeURIComponent(params.album)}
17+
<div className="absolute top-1/2 mt-10">
18+
{/* <video width={1000} height={1000} autoPlay src={`https://youtube.com/watch?v=${params.song}`} /> */}
19+
<iframe
20+
width="560"
21+
height="315"
22+
title={params.song}
23+
allowFullScreen
24+
src={`https://youtube.com/embed/${song?.videoId}?autoplay=1`}
25+
></iframe>
26+
</div>
27+
</Modal>
28+
);
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import Modal from "@example/shared/components/Modal";
2+
3+
type Props = {
4+
params: Promise<{
5+
artist: string;
6+
}>;
7+
};
8+
export default async function ArtistPage(props: Props) {
9+
const params = await props.params;
10+
return <Modal>Artists {params.artist}</Modal>;
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function Default() {
2+
return null;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { getSong } from "@example/shared/api";
2+
3+
type Props = {
4+
params: Promise<{
5+
album: string;
6+
song: string;
7+
}>;
8+
};
9+
export default async function Song(props: Props) {
10+
const params = await props.params;
11+
const song = await getSong(params.album, params.song);
12+
13+
return (
14+
<div>
15+
<h1>Not Modal</h1>
16+
{decodeURIComponent(params.album)}
17+
<iframe
18+
width="560"
19+
height="315"
20+
allowFullScreen
21+
src={`https://youtube.com/embed/${song?.videoId}?autoplay=1`}
22+
></iframe>
23+
</div>
24+
);
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function ArtistPage() {
2+
return <div>Artist</div>;
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { ReactNode } from "react";
2+
3+
export default function Layout({ children, modal }: { children: ReactNode; modal: ReactNode }) {
4+
return (
5+
<div>
6+
{children}
7+
{modal}
8+
</div>
9+
);
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { getAlbums } from "@example/shared/api";
2+
import Album from "@example/shared/components/Album";
3+
4+
export default async function AlbumPage() {
5+
const albums = await getAlbums();
6+
return (
7+
<div>
8+
{albums.map((album) => (
9+
<Album album={album} />
10+
))}
11+
</div>
12+
);
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { revalidateTag } from "next/cache";
2+
import { NextResponse, after } from "next/server";
3+
4+
export function POST() {
5+
after(
6+
() =>
7+
new Promise<void>((resolve) =>
8+
setTimeout(() => {
9+
revalidateTag("date");
10+
resolve();
11+
}, 5000)
12+
)
13+
);
14+
15+
return NextResponse.json({ success: true });
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { unstable_cache } from "next/cache";
2+
import { NextResponse } from "next/server";
3+
4+
export const dynamic = "force-static";
5+
6+
export async function GET() {
7+
const dateFn = unstable_cache(() => new Date().toISOString(), ["date"], {
8+
tags: ["date"],
9+
});
10+
const date = await dateFn();
11+
return NextResponse.json({ date });
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { NextResponse } from "next/server";
2+
3+
export async function GET(request: Request) {
4+
return NextResponse.json({
5+
hello: "client",
6+
});
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { NextResponse } from "next/server";
2+
3+
export async function GET(request: Request) {
4+
return NextResponse.json({
5+
url: request.url,
6+
});
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import fs from "node:fs/promises";
2+
import path from "node:path";
3+
import type { NextRequest } from "next/server";
4+
import { NextResponse } from "next/server";
5+
6+
export const dynamic = "force-dynamic";
7+
8+
// This endpoint simulates an on demand revalidation request
9+
export async function GET(request: NextRequest) {
10+
const cwd = process.cwd();
11+
const prerenderManifest = await fs.readFile(path.join(cwd, ".next/prerender-manifest.json"), "utf-8");
12+
const manifest = JSON.parse(prerenderManifest);
13+
const previewId = manifest.preview.previewModeId;
14+
15+
const result = await fetch(`https://${request.headers.get("host")}/isr`, {
16+
headers: { "x-prerender-revalidate": previewId },
17+
method: "HEAD",
18+
});
19+
20+
return NextResponse.json({
21+
status: 200,
22+
body: {
23+
result: result.ok,
24+
cacheControl: result.headers.get("cache-control"),
25+
},
26+
});
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { ImageResponse } from "next/og";
2+
// App router includes @vercel/og.
3+
// No need to install it.
4+
// ?title=<title>
5+
6+
export async function GET(request: Request) {
7+
try {
8+
const { searchParams } = new URL(request.url);
9+
10+
// ?title=<title>
11+
const hasTitle = searchParams.has("title");
12+
const title = hasTitle ? searchParams.get("title")?.slice(0, 100) : "My default title";
13+
14+
return new ImageResponse(
15+
(
16+
<div
17+
style={{
18+
backgroundColor: "black",
19+
backgroundSize: "150px 150px",
20+
height: "100%",
21+
width: "100%",
22+
display: "flex",
23+
textAlign: "center",
24+
alignItems: "center",
25+
justifyContent: "center",
26+
flexDirection: "column",
27+
flexWrap: "nowrap",
28+
}}
29+
>
30+
<div
31+
style={{
32+
display: "flex",
33+
alignItems: "center",
34+
justifyContent: "center",
35+
justifyItems: "center",
36+
}}
37+
>
38+
<img
39+
alt="Vercel"
40+
height={200}
41+
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"
42+
style={{ margin: "0 30px" }}
43+
width={232}
44+
/>
45+
</div>
46+
<div
47+
style={{
48+
fontSize: 60,
49+
fontStyle: "normal",
50+
letterSpacing: "-0.025em",
51+
color: "white",
52+
marginTop: 30,
53+
padding: "0 120px",
54+
lineHeight: 1.4,
55+
whiteSpace: "pre-wrap",
56+
}}
57+
>
58+
{title}
59+
</div>
60+
</div>
61+
),
62+
{
63+
width: 1200,
64+
height: 630,
65+
}
66+
);
67+
} catch (e: any) {
68+
return new Response("Failed to generate the image", {
69+
status: 500,
70+
});
71+
}
72+
}
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"use client";
2+
3+
import { useCallback, useState } from "react";
4+
5+
/**
6+
* Make /api/hello call exclusively on the client
7+
* - we already know SSR can fetch itself w/o issues
8+
*/
9+
export default function Page() {
10+
const [data, setData] = useState();
11+
12+
const onClientClick = useCallback(async () => {
13+
const { protocol, host } = window.location;
14+
const url = `${protocol}//${host}`;
15+
const r = await fetch(`${url}/api/client`);
16+
const d = await r.json();
17+
setData(d);
18+
}, []);
19+
20+
const onMiddlewareClick = useCallback(async () => {
21+
const { protocol, host } = window.location;
22+
const url = `${protocol}//${host}`;
23+
const r = await fetch(`${url}/api/middleware`);
24+
const d = await r.json();
25+
setData(d);
26+
}, []);
27+
28+
return (
29+
<div>
30+
<div>API: {data ? JSON.stringify(data, null, 2) : "N/A"}</div>
31+
32+
<button className="border p-2" onClick={onClientClick}>
33+
Call /api/client
34+
</button>
35+
<button className="border p-2" onClick={onMiddlewareClick}>
36+
Call /api/middleware
37+
</button>
38+
</div>
39+
);
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { revalidatePath } from "next/cache";
2+
3+
export const dynamic = "force-dynamic";
4+
5+
export async function GET() {
6+
revalidatePath("/revalidate-path");
7+
8+
return new Response("ok");
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { revalidateTag } from "next/cache";
2+
3+
export const dynamic = "force-dynamic";
4+
5+
export async function GET() {
6+
revalidateTag("revalidate");
7+
8+
return new Response("ok");
9+
}

0 commit comments

Comments
 (0)