Skip to content

Commit 922ac9e

Browse files
committed
add e2e
1 parent ab8d30c commit 922ac9e

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

examples/app-router/middleware.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ 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 === "/rewrite-status-code") {
32+
const u = new URL("/rewrite-destination", `${protocol}://${host}`);
33+
return NextResponse.rewrite(u, {
34+
status: 403,
35+
});
36+
}
3137
if (path === "/cookies") {
3238
const res = NextResponse.next();
3339
res.cookies.set("foo", "bar");

packages/tests-e2e/tests/appRouter/middleware.rewrite.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,12 @@ test("Middleware Rewrite External Image", async ({ page }) => {
3232
expect(validateMd5(bodyBuffer, OPENNEXT_PNG_MD5)).toBe(true);
3333
});
3434
});
35+
36+
test("Middleware Rewrite Status Code", async ({ page }) => {
37+
await page.goto("/rewrite-status-code");
38+
const el = page.getByText("Rewritten Destination", { exact: true });
39+
await expect(el).toBeVisible();
40+
page.on("response", async (response) => {
41+
expect(response.status()).toBe(403);
42+
});
43+
});

0 commit comments

Comments
 (0)