From 1e96a9784f1ff789837a1e43928aade7cf364aa0 Mon Sep 17 00:00:00 2001 From: Lorenzo Palmes Date: Tue, 28 May 2024 18:25:54 +0100 Subject: [PATCH] set cookie before responding (#7) --- middleware.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/middleware.ts b/middleware.ts index f4cc9e9..18ac0c2 100644 --- a/middleware.ts +++ b/middleware.ts @@ -26,6 +26,10 @@ export async function middleware(req: NextRequest) { if (process.env.NODE_ENV !== "production") { return NextResponse.next(); } + // Skip if the middleware has already run. + if (req.headers.get("x-deployment-override")) { + return getDeploymentWithCookieBasedOnEnvVar(); + } // We skip blue-green when accesing from deployment urls if (req.nextUrl.hostname === process.env.VERCEL_URL) { return NextResponse.next(); @@ -41,10 +45,6 @@ export async function middleware(req: NextRequest) { if (/vercel/i.test(req.headers.get("user-agent") || "")) { return NextResponse.next(); } - // Skip if the middleware has already run. - if (req.headers.get("x-deployment-override")) { - return getDeploymentWithCookieBasedOnEnvVar(); - } if (!process.env.EDGE_CONFIG) { console.warn("EDGE_CONFIG env variable not set. Skipping blue-green."); return NextResponse.next();