0.2.0 • Published 7 years ago

sails-hook-maintenance-mode v0.2.0

Weekly downloads
3
License
MIT
Repository
github
Last release
7 years ago

sails-hook-maintenance-mode

Sails JS hook to provide a simple "maintenance mode" for an app, toggleable with an environment variable. In maintenance mode, all requests receive an "under maintenance" page or message in response.

Installation

npm install sails-hook-maintenance-mode

Usage

To lift an app in maintenance mode, set the MAINTENANCE_MODE environment variable to "true".

MAINTENANCE_MODE=true sails lift

Configuration

By default, configuration lives in sails.config['maintenance-mode']. The configuration key (maintenance-mode) can be changed by setting sails.config.hooks['sails-hook-maintenance-mode'].configKey.

ParameterTypeDefaultDetails
envVar((string))MAINTENANCE_MODEEnvironment variable to check
view((string))noneView to display in maintenance mode. If not provided, the hook will use the views/maintenance.ejs view if your app has one. Otherwise, it will show a default maintenance page. Set to false to display text or JSON instead of a view (see text_message and json_message options)
viewLocals((dictionary)){}Locals and options to use with your maintenance view. You can use this to change up the message per environment, or to provide a different layout.
whitelistUrls((array))noneArray of strings or regular expressions to match a requested URL against. If the URL matches anything in the whitelist, it will bypass maintenance mode and be allowed to proceed. Useful for keeping certain sections of a site (like a contact page or FAQ) live.
status((number))503 (service unavailable)Status code to respond with in maintenance mode.
jsonMessage((json))noneIf view is set to false and json_message is provided, the res.json method will be used with that value for the response in maintenance mode.
textMessage((string))noneIf view is set to false and text_message is provided (and json_message is not provided), the res.send method will be used with that value for the response in maintenance mode.
backdoorOnParam((string))noneParameter which can be used to unlock maintenance mode for a single session. Use this to test updates to the site while the rest of the world still sees the maintenance page.
backdoorOffParam((string))noneParameter which can be used to re-instate maintenance mode for a session after the backdoor_on_param has been used.

Example

// [your-sails-app]/config/env/production.js
module.exports = {
  'maintenance-mode': {
    envVar: 'MAINTENANCE',
    view: false,
    textMessage: "Site currently under maintenance, please try again later."
    backdoorOnParam: 'open_sesame',
    backdoorOffParam: 'close_sesame',
    status: 200
  }
};