npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

express-maintenance-mode

v1.1.0

Published

Express middleware that allows you to put the server(s) in maintenance mode

Downloads

7

Readme

express-maintenance-mode

code coverage code style styled with prettier made with lass license npm downloads

Express middleware that allows you to put the server(s) in maintenance mode

Table of Contents

Motivation

I developed this module because I needed an easy way to transfer all servers behind the load balancer to maintenance mode with one API request. That is why I made methods for getting and setting external maintenance status. In my production environment, I use these techniques to keep the service status in sync with Redis. This way, all servers in the load balancing group are aware of the status update within a minute.

How it works

Module provides simple api to control maintenance state. Access to all middlewares below can be controlled by maintenance middleware

Install

npm:

npm install express-maintenance-mode

yarn:

yarn add express-maintenance-mode

Usage

import { ExpressMaintenanceMode } from 'express-maintenance-mode';

const maintenance = new ExpressMaintenanceMode<MaintenanceResponseBody>({
  maintenancePath: '/maintenance', // Path to control maintenance state
  apiBasePath: '/api', // Base path of your API
  accessKey: 'changeme', // Access key for maintenance endpoint. Works without authorization if not provided
  getExternalMaintenanceState: () => {
    // Optional
    // Your method to get external state
  },
  setExternalMaintenanceState: () => {
    // Optional
    // Your method to set external state
  },
  localMaintenanceStateTTL: 6000 // Lifetime of local maintenance state, until it be synced with external state
});

// Optional
interface MaintenanceResponseBody {
  message: string;
}

// App example

app.use(bodyParser.json());
app.use(maintenance.middleware)
// ...
app.use(yourGreatAPIRouter)

Redis example

import {MaintenanceState} from './index';

const getExternalMaintenanceState = async (): Promise<MaintenanceState<MaintenanceResponseBody>> => {
  return yourRedisDAO.get<MaintenanceState<MaintenanceResponseBody>>('maintenance');
}
  
const setExternalState = async (maintenanceState: MaintenanceState<MaintenanceResponseBody>) => {
  yourRedicDAO.save('maintenance', maintenanceState);
}

API

To control maintenance status three methods available:

GET - to get maintenance status POST - to set server in maintenance mode DELETE - to set server in regular mode

Using POST method you can set response status code and body

Request body:

{
  "statusCode": 503,
  "body": {
    "message": "Server in maintenance mode"
  }
}

Contributors

| Name | | ------------------- | | George Lykuanov |

License

Apache-2.0 © George Lykuanov