Anyone know an implementation of a Maintenance page similar to this
for a next.js application that wont require changing .env variables and redeploying each time site is switched on and off?
I would like to use an API response e.g siteStatus === 'down' or siteStatus === 'up' to set the maintenance page up.
I would appreciate any input on this because I have been stuck on it for a long time.
Changing the environment variable and redeploying the app is probably not a high price to pay considering the disadvantages of alternative approaches.
Here are some ideas and their disadvantages:
getInitialPropsin the_app, but you are going to lose static pages optimization.getStaticPropsin all your pages (you can add a HOC to streamline this process), and revalidate let's say every 10 minutes. But that would be an enormous overhead due to constant revalidation.MaintenanceGuardcomponent in the_appthat would delay rendering on the client until it fetches maintenance status. This approach would negatively affect time-to-interactive and UX in general.Now, I can see an acceptable implementation option if you can migrate your app to the Next 13
appdirectory.You'll need an external API endpoint hosted outside your app that would respond with maintenance status.
You can check maintenance status in the root layout of your app and conditionally display maintenance notification as follows.
To perform on-demand revalidation, you can create an API route that would trigger revalidation. To trigger revalidation, send a POST request to YOUR_HOST/api/maintenance endpoint.