Skip to content

Commit

Permalink
simplify middleware e2e check
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-piotrowicz committed Jan 24, 2025
1 parent 3fce074 commit 6e6d076
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
4 changes: 2 additions & 2 deletions examples/middleware/e2e/cloudflare-context.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { test, expect } from "@playwright/test";

test("cloudflare context env object is populated", async ({ page }) => {
test("middlewares have access to the cloudflare context", async ({ page }) => {
await page.goto("/middleware");
const cloudflareContextHeaderElement = page.getByTestId("cloudflare-context-header");
expect(await cloudflareContextHeaderElement.textContent()).toContain(
"variables from `cloudflareContext.env`: MY_KV, MY_VAR"
"typeof `cloudflareContext.env` = object"
);
});
5 changes: 1 addition & 4 deletions examples/middleware/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ export async function middleware(request: NextRequest, event: NextFetchEvent) {

requestHeaders.set(
"x-cloudflare-context",
`variables from \`cloudflareContext.env\`: ${Object.keys(cloudflareContext.env)
.filter((key) => key.startsWith("MY_"))
.sort()
.join(", ")}`
`typeof \`cloudflareContext.env\` = ${typeof cloudflareContext.env}`
);

return NextResponse.next({
Expand Down

0 comments on commit 6e6d076

Please sign in to comment.