Skip to content

Commit c308aed

Browse files
authored
sync with aws (#439)
* sync with aws * fix prettier
1 parent ff5cd39 commit c308aed

File tree

6 files changed

+63
-3
lines changed

6 files changed

+63
-3
lines changed

examples/e2e/pages-router/e2e/api.test.ts

100644100755
Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,40 @@ test("should not fail on an api route", async ({ page }) => {
44
const result = await page.goto("/api/hello");
55
expect(result?.status()).toBe(200);
66
const body = await result?.json();
7-
expect(body).toEqual({ hello: "world" });
7+
expect(body).toEqual({ hello: "OpenNext rocks!" });
8+
});
9+
10+
test("should work with dynamic api route", async ({ page }) => {
11+
const result = await page.goto("/api/dynamic/opennext");
12+
expect(result?.status()).toBe(200);
13+
const body = await result?.json();
14+
expect(body).toEqual({ slug: "opennext" });
15+
});
16+
17+
test("should work with catch all api route", async ({ page }) => {
18+
const result = await page.goto("/api/dynamic/catch-all/first/second/third");
19+
expect(result?.status()).toBe(200);
20+
const body = await result?.json();
21+
expect(body).toEqual({ slug: ["first", "second", "third"] });
22+
});
23+
24+
test("dynamic route should take precedence over catch all", async ({ page }) => {
25+
const result = await page.goto("/api/dynamic/catch-all");
26+
expect(result?.status()).toBe(200);
27+
const body = await result?.json();
28+
expect(body).toEqual({ slug: "catch-all" });
29+
});
30+
31+
test("should work with optional catch all api route", async ({ page }) => {
32+
const result = await page.goto("/api/dynamic/catch-all-optional");
33+
expect(result?.status()).toBe(200);
34+
const body = await result?.json();
35+
expect(body).toEqual({ optional: "true" });
36+
});
37+
38+
test("predefined api route should take presedence", async ({ page }) => {
39+
const result = await page.goto("/api/dynamic/precedence");
40+
expect(result?.status()).toBe(200);
41+
const body = await result?.json();
42+
expect(body).toEqual({ precedence: "true" });
843
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import type { NextApiRequest, NextApiResponse } from "next";
2+
3+
export default function handler(req: NextApiRequest, res: NextApiResponse) {
4+
const { slug } = req.query;
5+
res.status(200).json({ slug });
6+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { NextApiRequest, NextApiResponse } from "next";
2+
3+
export default function handler(req: NextApiRequest, res: NextApiResponse) {
4+
res.status(200).json({ optional: "true" });
5+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import type { NextApiRequest, NextApiResponse } from "next";
2+
3+
export default function handler(req: NextApiRequest, res: NextApiResponse) {
4+
const { slug } = req.query;
5+
if (!Array.isArray(slug)) {
6+
return res.status(500).json({ error: "Invalid" });
7+
}
8+
res.status(200).json({ slug });
9+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import type { NextApiRequest, NextApiResponse } from "next";
2+
3+
export default function handler(req: NextApiRequest, res: NextApiResponse) {
4+
res.status(200).json({ precedence: "true" });
5+
}

examples/e2e/pages-router/src/pages/api/hello.ts

100644100755
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
1+
// Next.js API route support: https://nextjs.org/docs/pages/building-your-application/routing/api-routes
22
import type { NextApiRequest, NextApiResponse } from "next";
33

44
type Data = {
55
hello: string;
66
};
77

88
export default function handler(req: NextApiRequest, res: NextApiResponse<Data>) {
9-
res.status(200).json({ hello: "world" });
9+
res.status(200).json({ hello: "OpenNext rocks!" });
1010
}

0 commit comments

Comments
 (0)