Skip to content

Commit

Permalink
set cookie before responding (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpalmes authored May 28, 2024
1 parent 043e34b commit 1e96a97
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 1e96a97

Please sign in to comment.