Last active
October 3, 2023 03:32
-
-
Save naotone/014038835854374917a73701ef195e3b to your computer and use it in GitHub Desktop.
Maintenance mode redirection for next.js
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 { GetServerSideProps } from 'next' | |
import React from 'react' | |
import Head from 'next/head' | |
import Header from '../components/header' | |
import Footer from '../components/footer' | |
const Layout: React.FunctionComponent = () => ( | |
<> | |
<Head> | |
<title></title> | |
</Head> | |
<div> | |
<> | |
<Header /> | |
<main> | |
<p>Maintenance</p> | |
</main> | |
<Footer /> | |
</> | |
</div> | |
</> | |
) | |
export default Layout | |
export const getServerSideProps: GetServerSideProps = async (context) => { | |
const { res } = context | |
res.statusCode = 503 | |
return { props: {} } | |
} |
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
redirects() { | |
return [ | |
process.env.MAINTENANCE_MODE | |
? { | |
source: '/((?!maintenance|_next).*)', | |
destination: '/maintenance', | |
permanent: false, | |
} | |
: null, | |
process.env.MAINTENANCE_MODE | |
? { | |
source: '/(maintenance/.*)', | |
destination: '/maintenance', | |
permanent: false, | |
} | |
: null, | |
].filter(Boolean) | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
heyHello, may I ask how to apply this page maintenance to the project? Should it be placed in the root folder?