https://github.com/ladjs/koa-better-timeout
Response timeout middleware for Koa and Lad (uses Boom by default)
https://github.com/ladjs/koa-better-timeout
api koa lad middleware ms response settimeout time timeout timer
Last synced: 10 months ago
JSON representation
Response timeout middleware for Koa and Lad (uses Boom by default)
- Host: GitHub
- URL: https://github.com/ladjs/koa-better-timeout
- Owner: ladjs
- License: mit
- Created: 2017-09-09T19:29:09.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-07-23T01:53:29.000Z (over 5 years ago)
- Last Synced: 2025-04-02T12:01:42.633Z (11 months ago)
- Topics: api, koa, lad, middleware, ms, response, settimeout, time, timeout, timer
- Language: JavaScript
- Homepage: https://lad.js.org
- Size: 304 KB
- Stars: 4
- Watchers: 7
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# koa-better-timeout
[](https://travis-ci.org/ladjs/koa-better-timeout)
[](https://codecov.io/gh/ladjs/koa-better-timeout)
[](https://github.com/sindresorhus/xo)
[](https://github.com/prettier/prettier)
[](https://lass.js.org)
[](<>)
> Response timeout middleware for [Koa][] and [Lad][] (uses [Boom][] by default)
## Table of Contents
* [Install](#install)
* [Usage](#usage)
* [Options](#options)
* [Contributors](#contributors)
* [License](#license)
## Install
[npm][]:
```sh
npm install koa-better-timeout
```
[yarn][]:
```sh
yarn add koa-better-timeout
```
## Usage
> 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);
```
## Options
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.
## Contributors
| Name | Website |
| -------------- | -------------------------- |
| **Nick Baugh** | |
## License
[MIT](LICENSE) © [Nick Baugh](http://niftylettuce.com/)
##
[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/