Skip to content

Instantly share code, notes, and snippets.

@nehemiahj
Created March 14, 2024 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nehemiahj/66327274c10fff78e2a32505dd8b115c to your computer and use it in GitHub Desktop.
Save nehemiahj/66327274c10fff78e2a32505dd8b115c to your computer and use it in GitHub Desktop.
Vercel Edge Config - Middleware
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