-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,50 @@ | ||
export { default } from "next-auth/middleware"; | ||
import { get } from "@vercel/edge-config"; | ||
import { NextResponse } from "next/server"; | ||
import type { NextRequest } from "next/server"; | ||
|
||
export const config = { matcher: ["/user/(.*)", "/admin/(.*)"] }; | ||
export const config = { | ||
matcher: [ | ||
/* | ||
* Match all request paths except for the ones starting with: | ||
* - api (API routes) | ||
* - _next/static (static files) | ||
* - _next/image (image optimization files) | ||
* - favicon.ico (favicon file) | ||
*/ | ||
{ | ||
source: "/((?!api|_next/static|_next/image|favicon.ico).*)?", | ||
missing: [ | ||
{ type: "header", key: "next-router-prefetch" }, | ||
{ type: "header", key: "purpose", value: "prefetch" }, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
export async function middleware(request: NextRequest) { | ||
let isInMaintenanceMode = false; | ||
|
||
try { | ||
isInMaintenanceMode = | ||
// Don't show the maintenance page in development | ||
process.env.VERCEL_ENV === "production" && | ||
// Check Edge Config to see if the maintenance page should be shown | ||
((await get("maintenanceMode")) ?? false); | ||
} catch (e) { | ||
// Edge Config not accessible, log the error | ||
console.error(e); | ||
} | ||
|
||
if (isInMaintenanceMode) { | ||
request.nextUrl.pathname = `/maintenance`; | ||
return NextResponse.rewrite(request.nextUrl); | ||
} | ||
|
||
const response = NextResponse.next({ | ||
request: { | ||
headers: request.headers, | ||
}, | ||
}); | ||
|
||
return response; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import Head from "next/head"; | ||
|
||
export default function Maintenance() { | ||
return ( | ||
<> | ||
<Head> | ||
<title>Maintenance Mode - ImprovDB</title> | ||
</Head> | ||
<div className="min-h-full"> | ||
<main> | ||
<div className="relative mx-auto max-w-7xl p-6 text-center lg:pt-12"> | ||
<h1 className="scroll-m-20 text-4xl font-extrabold tracking-tight lg:text-5xl"> | ||
Under Maintenance | ||
</h1> | ||
<p className="mt-6 leading-7"> | ||
The website is undergoing scheduled maintenance. Please try | ||
reloading the page in a few minutes. | ||
</p> | ||
</div> | ||
</main> | ||
</div> | ||
</> | ||
); | ||
} |
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
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
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