Response timeout middleware for Koa and Lad (uses Boom by default)
npm install koa-better-timeout





> Response timeout middleware for [Koa][] and [Lad][] (uses [Boom][] by default)
* Install
* Usage
* Options
* Contributors
* License
[npm][]:
``sh`
npm install koa-better-timeout
[yarn][]:
`sh`
yarn add koa-better-timeout
> Default middleware usage:
`js
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][ladjs-i18n] middleware) with translated response message:
`js
const Timeout = require('koa-better-timeout');
// ...
const timeout = new Timeout({
message: ctx => ctx.translate('REQUEST_TIMED_OUT')
});
app.use(timeout.middleware);
`
You can optionally pass an object of options to Timeout(opts).
The default option values use [Boom][] and are:
`js`
{
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.
| Name | Website |
| -------------- | -------------------------- |
| Nick Baugh |
##
[npm]: https://www.npmjs.com/
[yarn]: https://yarnpkg.com/
[lad]: https://lad.js.org
[boom]: https://github.com/hapijs/boom
[ladjs-i18n]: https://github.com/ladjs/i18n
[koa]: http://koajs.com/