Skip to content

Commit 885ef02

Browse files
authored
chores bump and sync with aws (#651)
* sync #858 * sync aws#851 * sync aws#844 and aws#855 * linting * bump to aws 3.6.1
1 parent a20d2df commit 885ef02

File tree

14 files changed

+300
-72
lines changed

14 files changed

+300
-72
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
export default async function RewriteDestination(props: { searchParams: Promise<{ a: string }> }) {
1+
export default async function RewriteDestination(props: {
2+
searchParams: Promise<{ a: string; multi?: string[] }>;
3+
}) {
24
const searchParams = await props.searchParams;
35
return (
46
<div>
57
<div>Rewritten Destination</div>
68
<div>a: {searchParams.a}</div>
9+
<div>multi: {searchParams.multi?.join(", ")}</div>
710
</div>
811
);
912
}
Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,42 @@
11
import { expect, test } from "@playwright/test";
22

3-
test("Middleware Rewrite", async ({ page }) => {
4-
await page.goto("/");
5-
await page.locator('[href="/rewrite"]').click();
3+
test.describe("Middleware Rewrite", () => {
4+
test("Simple Middleware Rewrite", async ({ page }) => {
5+
await page.goto("/");
6+
await page.locator('[href="/rewrite"]').click();
67

7-
await page.waitForURL("/rewrite");
8-
let el = page.getByText("Rewritten Destination", { exact: true });
9-
await expect(el).toBeVisible();
10-
el = page.getByText("a: b", { exact: true });
11-
await expect(el).toBeVisible();
12-
// Loading page should also rewrite
13-
await page.goto("/rewrite");
14-
await page.waitForURL("/rewrite");
15-
el = page.getByText("Rewritten Destination", { exact: true });
16-
await expect(el).toBeVisible();
17-
el = page.getByText("a: b", { exact: true });
18-
await expect(el).toBeVisible();
8+
await page.waitForURL("/rewrite");
9+
let el = page.getByText("Rewritten Destination", { exact: true });
10+
await expect(el).toBeVisible();
11+
el = page.getByText("a: b", { exact: true });
12+
await expect(el).toBeVisible();
13+
// Loading page should also rewrite
14+
await page.goto("/rewrite");
15+
await page.waitForURL("/rewrite");
16+
el = page.getByText("Rewritten Destination", { exact: true });
17+
await expect(el).toBeVisible();
18+
el = page.getByText("a: b", { exact: true });
19+
await expect(el).toBeVisible();
20+
});
21+
22+
test("Middleware Rewrite with multiple search params", async ({ page }) => {
23+
await page.goto("/rewrite-multi-params");
24+
let el = page.getByText("Rewritten Destination", { exact: true });
25+
await expect(el).toBeVisible();
26+
el = page.getByText("a: b", { exact: true });
27+
await expect(el).toBeVisible();
28+
el = page.getByText("multi: 0, 1, 2", { exact: true });
29+
await expect(el).toBeVisible();
30+
});
31+
32+
test("Middleware Rewrite should override original search params", async ({ page }) => {
33+
await page.goto("/rewrite?a=1&multi=3");
34+
let el = page.getByText("Rewritten Destination", { exact: true });
35+
await expect(el).toBeVisible();
36+
el = page.getByText("a: b", { exact: true });
37+
await expect(el).toBeVisible();
38+
el = page.getByText("multi:", { exact: true });
39+
await expect(el).toBeVisible();
40+
await expect(el).toHaveText("multi:");
41+
});
1942
});

examples/e2e/app-pages-router/middleware.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ export function middleware(request: NextRequest) {
2727
u.searchParams.set("a", "b");
2828
return NextResponse.rewrite(u);
2929
}
30+
if (path === "/rewrite-multi-params") {
31+
const u = new URL("/rewrite-destination", `${protocol}://${host}`);
32+
u.searchParams.append("multi", "0");
33+
u.searchParams.append("multi", "1");
34+
u.searchParams.append("multi", "2");
35+
u.searchParams.set("a", "b");
36+
return NextResponse.rewrite(u);
37+
}
3038
if (path === "/api/middleware") {
3139
return new NextResponse(JSON.stringify({ hello: "middleware" }), {
3240
status: 200,
@@ -43,6 +51,19 @@ export function middleware(request: NextRequest) {
4351
},
4452
});
4553
}
54+
55+
if (path === "/head" && request.method === "HEAD") {
56+
return new NextResponse(null, {
57+
headers: {
58+
"x-from-middleware": "true",
59+
},
60+
});
61+
}
62+
63+
if (path === "/fetch") {
64+
// This one test both that we don't modify immutable headers
65+
return fetch(new URL("/api/hello", request.url));
66+
}
4667
const rHeaders = new Headers(request.headers);
4768
const r = NextResponse.next({
4869
request: {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { cookies } from "next/headers";
2+
3+
export default async function Page() {
4+
const foo = (await cookies()).get("foo")?.value;
5+
6+
return <div data-testid="foo">{foo}</div>;
7+
}
Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
import { expect, test } from "@playwright/test";
22

3-
test("Cookies", async ({ page, context }) => {
4-
await page.goto("/");
3+
test.describe("Middleware Cookies", () => {
4+
test("should be able to set cookies on response in middleware", async ({ page, context }) => {
5+
await page.goto("/");
56

6-
const cookies = await context.cookies();
7-
const from = cookies.find(({ name }) => name === "from");
8-
expect(from?.value).toEqual("middleware");
7+
const cookies = await context.cookies();
8+
const from = cookies.find(({ name }) => name === "from");
9+
expect(from?.value).toEqual("middleware");
910

10-
const love = cookies.find(({ name }) => name === "with");
11-
expect(love?.value).toEqual("love");
11+
const love = cookies.find(({ name }) => name === "with");
12+
expect(love?.value).toEqual("love");
13+
});
14+
test("should be able to get cookies set in the middleware with Next's cookies().get()", async ({
15+
page,
16+
}) => {
17+
await page.goto("/cookies");
18+
19+
expect(await page.getByTestId("foo").textContent()).toBe("bar");
20+
});
21+
test("should not expose internal Next headers in response", async ({ page, context }) => {
22+
const responsePromise = page.waitForResponse((response) => response.url().includes("/cookies"));
23+
24+
await page.goto("/cookies");
25+
26+
const response = await responsePromise;
27+
const headers = response.headers();
28+
29+
const cookies = await context.cookies();
30+
const fooCookie = cookies.find(({ name }) => name === "foo");
31+
expect(fooCookie?.value).toBe("bar");
32+
33+
expect(headers).not.toHaveProperty("x-middleware-set-cookie");
34+
expect(headers).not.toHaveProperty("x-middleware-next");
35+
});
1236
});

examples/e2e/app-router/middleware.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ export function middleware(request: NextRequest) {
2828
const u = new URL("https://opennext.js.org/share.png");
2929
return NextResponse.rewrite(u);
3030
}
31+
if (path === "/cookies") {
32+
const res = NextResponse.next();
33+
res.cookies.set("foo", "bar");
34+
return res;
35+
}
3136
const requestHeaders = new Headers(request.headers);
3237
// Setting the Request Headers, this should be available in RSC
3338
requestHeaders.set("request-header", "request-header");
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { expect, test } from "@playwright/test";
2+
3+
test.describe("fallback", () => {
4+
test("should work with fully static fallback", async ({ page }) => {
5+
await page.goto("/fallback-intercepted/static/");
6+
const h1 = page.locator("h1");
7+
await expect(h1).toHaveText("Static Fallback Page");
8+
const p = page.getByTestId("message");
9+
await expect(p).toHaveText("This is a fully static page.");
10+
});
11+
12+
test("should work with static fallback", async ({ page }) => {
13+
await page.goto("/fallback-intercepted/ssg/");
14+
const h1 = page.locator("h1");
15+
await expect(h1).toHaveText("Static Fallback Page");
16+
const p = page.getByTestId("message");
17+
await expect(p).toHaveText("This is a static ssg page.");
18+
});
19+
20+
test("should work with fallback intercepted by dynamic route", async ({ page }) => {
21+
await page.goto("/fallback-intercepted/something/");
22+
const h1 = page.locator("h1");
23+
await expect(h1).toHaveText("Dynamic Fallback Page");
24+
const p = page.getByTestId("message");
25+
await expect(p).toHaveText("This is a dynamic fallback page.");
26+
});
27+
28+
test("should work with fallback page pregenerated", async ({ page }) => {
29+
await page.goto("/fallback-intercepted/fallback/");
30+
const h1 = page.locator("h1");
31+
await expect(h1).toHaveText("Static Fallback Page");
32+
const p = page.getByTestId("message");
33+
await expect(p).toHaveText("This is a static fallback page.");
34+
});
35+
36+
test("should 404 on page not pregenerated", async ({ request }) => {
37+
const res = await request.get("/fallback/not-generated");
38+
expect(res.status()).toBe(404);
39+
});
40+
});
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { InferGetServerSidePropsType } from "next";
2+
3+
export function getServerSideProps() {
4+
return {
5+
props: {
6+
message: "This is a dynamic fallback page.",
7+
},
8+
};
9+
}
10+
11+
export default function Page({ message }: InferGetServerSidePropsType<typeof getServerSideProps>) {
12+
return (
13+
<div>
14+
<h1>Dynamic Fallback Page</h1>
15+
<p data-testid="message">{message}</p>
16+
</div>
17+
);
18+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { InferGetStaticPropsType } from "next";
2+
3+
export function getStaticPaths() {
4+
return {
5+
paths: [
6+
{
7+
params: {
8+
slug: "fallback",
9+
},
10+
},
11+
],
12+
fallback: false,
13+
};
14+
}
15+
16+
export function getStaticProps() {
17+
return {
18+
props: {
19+
message: "This is a static fallback page.",
20+
},
21+
};
22+
}
23+
24+
export default function Page({ message }: InferGetStaticPropsType<typeof getStaticProps>) {
25+
return (
26+
<div>
27+
<h1>Static Fallback Page</h1>
28+
<p data-testid="message">{message}</p>
29+
</div>
30+
);
31+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { InferGetStaticPropsType } from "next";
2+
3+
export function getStaticProps() {
4+
return {
5+
props: {
6+
message: "This is a static ssg page.",
7+
},
8+
};
9+
}
10+
11+
export default function Page({ message }: InferGetStaticPropsType<typeof getStaticProps>) {
12+
return (
13+
<div>
14+
<h1>Static Fallback Page</h1>
15+
<p data-testid="message">{message}</p>
16+
</div>
17+
);
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default function Page() {
2+
return (
3+
<div>
4+
<h1>Static Fallback Page</h1>
5+
<p data-testid="message">This is a fully static page.</p>
6+
</div>
7+
);
8+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import type { InferGetStaticPropsType } from "next";
2+
3+
export function getStaticPaths() {
4+
return {
5+
paths: [
6+
{
7+
params: {
8+
slug: "fallback",
9+
},
10+
},
11+
],
12+
fallback: false,
13+
};
14+
}
15+
16+
export function getStaticProps() {
17+
return {
18+
props: {
19+
message: "This is a static fallback page.",
20+
},
21+
};
22+
}
23+
24+
export default function Page({ message }: InferGetStaticPropsType<typeof getStaticProps>) {
25+
return (
26+
<div>
27+
<h1>Static Fallback Page</h1>
28+
<p data-testid="message">{message}</p>
29+
</div>
30+
);
31+
}

packages/cloudflare/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
"homepage": "https://github.com/opennextjs/opennextjs-cloudflare",
5454
"dependencies": {
5555
"@dotenvx/dotenvx": "catalog:",
56-
"@opennextjs/aws": "https://pkg.pr.new/@opennextjs/aws@859",
56+
"@opennextjs/aws": "^3.6.1",
5757
"enquirer": "^2.4.1",
5858
"glob": "catalog:",
5959
"ts-tqdm": "^0.8.6"

0 commit comments

Comments
 (0)