Created
March 14, 2024 21:32
-
-
Save nehemiahj/66327274c10fff78e2a32505dd8b115c to your computer and use it in GitHub Desktop.
Vercel Edge Config - Middleware
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NextRequest, NextResponse } from "next/server"; | |
import { get } from "@vercel/edge-config"; | |
export const config = { | |
matcher: "/payment", | |
}; | |
export async function middleware(req: NextRequest) { | |
// Check Edge Config to see if the maintenance page should be shown | |
const isInMaintenanceMode = await get("isInMaintenanceMode"); | |
// If in maintenance mode, point the url pathname to the maintenance page | |
if (isInMaintenanceMode) { | |
req.nextUrl.pathname = `/maintenance`; | |
// Rewrite to the url | |
return NextResponse.rewrite(req.nextUrl); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment