Introducing Socket Firewall: Free, Proactive Protection for Your Software Supply Chain.Learn More
Socket
Book a DemoInstallSign in
Socket

koa-graceful-shutdown

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

koa-graceful-shutdown

Ensure that during shutdown Koa returns correctly with a 503

latest
Source
npmnpm
Version
1.2.1
Version published
Maintainers
1
Created
Source

koa-graceful-shutdown

NPM CI

Ensure that during shutdown Koa returns correctly with a HTTP 503 Service Unavailable. Based off express-graceful-shutdown with the middleware adapted for Koa.

const http = require('http');
const Koa = require('koa');
const shutdown = require('koa-graceful-shutdown');

const app = new Koa();
const server = http.createServer(app.callback());

app.use(shutdown(server));

app.use(ctx => {
  ctx.status = 200;
  ctx.body = { foo: 'bar' };
});

server.listen(0, 'localhost', () => {
  const { address, port } = server.address();
  console.log('Listening on http://%s:%d', address, port);
});

Install

npm install koa-graceful-shutdown --save

Arguments

shutdown(server, opts) => function(ctx, next)
ArgumentDescription
serverhttp.server
optsOptional options
opts.loggerA logger that provides info, warn and error methods, defaults to console
opts.forceTimeoutMilliseconds to wait for server.close() to finish, defaults to 30000

Notes

FAQs

Package last updated on 06 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts