# koa-timeout-v2

> Middleware of Koa v2, 408 "request time-out" will be return if request execute timeout, ctx.state.timeout will be set to ture at same time.

Latest version **1.0.0** (published 2016-11-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install koa-timeout-v2
pnpm add koa-timeout-v2
yarn add koa-timeout-v2
bun add koa-timeout-v2
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-11-20 |
| First published | 2016-11-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 7 |
| Author | shenyu1997@gmail.com |
| Maintainers | shenyu1997 |
| Keywords | timeout, koa, v2 |

## Links

- npm: https://www.npmjs.com/package/koa-timeout-v2
- Repository: https://github.com/js-fullstack/koa-timeout-v2
- Homepage: https://github.com/js-fullstack/koa-timeout-v2#readme
- Issues: https://github.com/js-fullstack/koa-timeout-v2/issues
- npm.io page: https://npm.io/package/koa-timeout-v2

## Dependencies (1)

- [http-errors](https://npm.io/package/http-errors.md) ^1.5.1

## Recent versions

- 1.0.0 (latest) — 2016-11-20

## README

# koa-timeout-v2
Middleware of Koa v2, 408 "request time-out" will be return if request execute timeout, ctx.state.timeout will be set to ture at same time.

## Install
npm install koa-timeout-v2

## API

```
timeout(delay, options)
```
##### delay: time out (ms)
##### option: {status, message, callback}


## Sample

#### Simple
```
const timeout = require('koa-timeout-v2');
const Koa = require('koa');
const app = new Koa();

app.use(timeout(5000)) ;
```

#### With callback
```
const timeout = require('koa-timeout-v2');
const Koa = require('koa');
const app = new Koa();

function callback(ctx, delay) {
  //TODO timeout handle
}

app.use(timeout(5000,{callback})) ;
```

#### use ctx.state.timeout
```
const timeout = require('koa-timeout-v2');
const Koa = require('koa');
const app = new Koa();

function stop() {
  return async (ctx, next) => {
    if(!ctx.state.timeout) {
      await next();
    }
  }
}

app.use(timeout(5000)) ;
app.use(stop());
app.use(bodyParse());
app.use(stop());
...
```

#### Customize error
```
const timeout = require('koa-timeout-v2');
const Koa = require('koa');
const app = new Koa();

app.use(timeout(5000,{status:503, message:'service unavailable'})) ;
```

---
_Source: https://npm.io/package/koa-timeout-v2 · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
