adonisjs-maintenance
TypeScript icon, indicating that this package has built-in type declarations

2.0.2 • Public • Published

adonisjs-maintenance

A maintenance mode for the AdonisJS framework

npm-image license-image typescript-image

This NPM package allows you to integrate a maintenance mode for your AdonisJS application - with one single command. Ability to bypass and setting a maintenance message included.

Installation

Install

npm i adonisjs-maintenance

Configure:

node ace configure adonisjs-maintenance

This will add

  • adonisjs-maintenance/CheckForMaintenanceMode as router middleware
  • adonisjs-maintenance/commands to commands
  • adonisjs-maintenance/MaintenanceProvider as extra service provider

to your application

Usage

Toggle maintenance mode

Execute the command node ace maintenance

Available flags:

  --secret string   Secret key to bypass maintenance mode
  --message string  Custom message for maintenance mode
  • The secret can be passed via a GET parameter named 'secret' (localhost:3333/?secret=mysecret) or the header X-Maintenance-Secret
  • When maintenance mode is enabled, all requests to the application will have a 503 status (api, web, ...)

Optional: custom error views

This package throws an exception to show a 503 status. Which means you can use status pages which AdonisJS provides.

You can check out this behaviour in the file app/exceptions/handler.ts of your app. By default it'll show the edge template pages/errors/server_error when a 503 HTTP error occurs:

protected statusPages: Record<StatusPageRange, StatusPageRenderer> = {
    //...

    '500..599': (error, { view }) => {
        return view.render('pages/errors/server_error', { error })
    },
  }

But you can create a new edge template for only the 503 status like so:

protected statusPages: Record<StatusPageRange, StatusPageRenderer> = {
    //...
    '503': (error, { view }) => {
        return view.render('pages/errors/maintenance', { error })
    },
    '504..599': (error, { view }) => {
        return view.render('pages/errors/server_error', { error })
    },
}

The custom message can be shown in the view like so:

<h1>{{ error.status }} - Maintenance </h1>
<p>Maintenance mode activated, please come back later.</p>
<p>
    {{ error.message }}
</p>

Package Sidebar

Install

npm i adonisjs-maintenance

Weekly Downloads

51

Version

2.0.2

License

MIT

Unpacked Size

13.7 kB

Total Files

16

Last publish

Collaborators

  • michaelbelgium