Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including koa-better-timeout with all npm packages installed. Try it out:

var koaBetterTimeout = require("koa-better-timeout")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

koa-better-timeout v0.0.4

Response timeout middleware for Koa and Lad (uses Boom by default)

koa-better-timeout

build status code coverage code style styled with prettier made with lass license

Response timeout middleware for Koa and Lad (uses Boom by default)

Table of Contents

Install

npm:

npm install koa-better-timeout

yarn:

yarn add koa-better-timeout

Usage

Default middleware usage:

const Timeout = require('koa-better-timeout');

// ...

const timeout = new Timeout();
app.use(timeout.middleware);

Advanced middleware usage (e.g. using Lad and its @ladjs/i18n middleware) with translated response message:

const Timeout = require('koa-better-timeout');

// ...

const timeout = new Timeout({
  message: ctx => ctx.translate('REQUEST_TIMED_OUT')
});
app.use(timeout.middleware);

Options

You can optionally pass an object of options to Timeout(opts).

The default option values use Boom and are:

{
  ms: 6000,
  message: Boom.clientTimeout().message,
  sendResponse: Boom.clientTimeout
}

Note that message can be a function that accepts one argument ctx. This is useful if you wish to use i18n translation for the response message.

Contributors

NameWebsite
Nick Baughhttp://niftylettuce.com/

License

MIT © Nick Baugh

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free