Our maintenance switch is a boolean in the repository, because the database is the thing that is down
PubTrivia is a live quiz product. A host launches a question, sixty phones in a pub answer it, and the leaderboard moves. All of that needs Postgres and an auth provider, which means there is a class of maintenance, a migration, a provider incident, a region move, where the honest thing to show is a page that says so. So we added a maintenance switch. The whole thing is three exported values:…
Our maintenance switch in the repository is a simple boolean set to false in a file named lib/maintenance.ts. This constant is flipped by hand and deployed, rather than being stored as a row in a settings table or retrieved from a flag service. The switch is used to indicate when PubTrivia is down for maintenance, providing a user-friendly message when the database is unavailable.
Turning on maintenance requires a redeploy, while turning it off requires another, but this cost is acceptable for a product that schedules its own migrations. Turning maintenance on eliminates the need for rate limit checks and session refreshes, resulting in faster response times. The maintenance page is rendered for all requests except for static pages, such as the marketing site, feature pages, hosting guide, legal documents, and certain API routes and webhooks.
The maintenance page is rewritten rather than redirected to maintain the URL structure and improve the user experience. For POST requests from open tabs, the method is checked before the rewrite, preventing framework errors. The login, signup, and forgot-password pages are excluded from the maintenance page to provide a better user experience and ensure a seamless process for users.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.