reactjsreact-routermaintenance-modemaintenance-plan

How to handle maintenance process with React


Here is my app’s current way to handle the maintenance process:

I have an environment variable for the app status:

REACT_APP_SITE_MODE=“LIVE” | “MAINTENANCE”

I'm using react-router for routing the app:

switch (process.env.REACT_APP_SITE_MODE) {
  case "MAINTENANCE":
    return (
      <Switch>
        <Route component={MaintenancePage} />
      </Switch>
    );
  default:
    return (
      <Switch>
        {/* Default routes */}
      </Switch>
    );
}

This works fine but when we just switch it to the maintenance mode, some users can still access the app with the default routes (this is not good when the backend is down), I think it’s because of the browser cache or something.

My question is:

  1. How to prevent users from accessing the app during the maintenance period? (force them to clear their cache in that specific time?)
  2. Is there a better way to handle the maintenance process?

Thanks.


Solution

  • I think your best bet is to have your maintenance state for both BE and FE:

    So in the case of having a browser caching (your scenario), even though it can go to normal routes, the next time the FE sends a request to BE, it will be redirected to your maintenance page.