Tomsize
Tomsize
TTCTheo's Typesafe Cult
Created by bennettdev on 4/8/2023 in #questions
How to disable site/deployment/auth temporarily? (Vercel)
You could use the new Edge Config store from Vercel and redirect users to a maintenance page from the middleware. This way you could dynamically disable the whole website or some specific routes. The only cons is that you would have to read the store on every request matched by the middleware (which is really fast!), but it might increase the bill (you have 1 million free read with Pro, then it's 3$ per million) https://vercel.com/docs/concepts/edge-network/edge-config/get-started
// middleware.ts

import { NextResponse } from 'next/server';
import { get } from '@vercel/edge-config';

export const config = { matcher: "/" };

export async function middleware(request: NextRequest) {
const isMaintenance = get('maintenance');

if (isMaintenance) {
return NextResponse.redirect('/maintenance');
}

return NextResponse.next();
};
// middleware.ts

import { NextResponse } from 'next/server';
import { get } from '@vercel/edge-config';

export const config = { matcher: "/" };

export async function middleware(request: NextRequest) {
const isMaintenance = get('maintenance');

if (isMaintenance) {
return NextResponse.redirect('/maintenance');
}

return NextResponse.next();
};
5 replies