DEV Community

Cover image for ExpressWebJs Maintenance Mode
Chukwuemeka Igbokwe
Chukwuemeka Igbokwe

Posted on

ExpressWebJs Maintenance Mode

In this tutorial, I will show you how to switch your ExpressWebJs application to maintenance mode, and also how to change the default ExpressWebJs maintenance mode message to your custom message.

More often than not you would need to perform some maintenance for your ExpressWebJs application, luckily ExpressWebJs makes it super easy to put your application in maintenance mode.

You can switch your application to maintenance mode in Config/app.ts file.

  | Application maintenance mode
  | Mode ==> Determine if application is in maintenance mode 
  |    or not. Default value is false
  | Message ==> The message to render while in maintenance 
  |    mode.
  | Retry ==> The number of seconds after which the request 
  |    may be retried
  | Endpoints ==> The endPoints that should be reachable while 
  |    maintenance mode is enabled.
  |    endpoints example: ['api/users','api/accounts']
  maintenanceMode: {
    mode: true, //enable and disable maintenance mode
    message: "Application is in maintenance mode.",
    retry: 50,
    endPoints: [],
Enter fullscreen mode Exit fullscreen mode

When your application is in maintenance mode, a default message "Application is in maintenance mode" will be sent as a response to all requests accessing your application. This makes it easy to "disable" your application on downtime.

This downtime could be for a lot of reasons, including but not limited to:

  1. Bugs.
  2. Database error.
  3. Migration to another server.
  4. Server upgrade.
  5. Decoupling to a new architecture.
  6. SSL Error.
  7. Updating Application etc.

A maintenance mode check is included in the default middleware stack for your application. If the application is in maintenance mode, a MaintenanceModeException will be thrown with a status code of 503.

To read more about ExpressWebJs, visit the Documentation site at ExpressWebJs .
You can also join the Discord community

You can follow me on twitter @EmekaIgbokwe
You can follow ExpressWebJs on twitter @expresswebjs
and don't forget to star on github ExpressWebJs

Please, let me know if you have any questions in the comment section. 😊

Top comments (0)