0.1.1 • Published 9 years ago

koa-timeout v0.1.1

Weekly downloads
124
License
MIT
Repository
github
Last release
9 years ago

koa-timeout

Timeout middleware for koa.

Will throw "Request timeout" (Http 408) for any requests that take too long.

Installation

$ npm install koa-timeout

Example

If we always want to respond within half a second, we could use timeout(500) as middleware after our error handler:

var koa = require('koa');
var timeout = require('koa-timeout')(500);

var app = koa();
app.use(function * tryCatch(next) {
  try {
    yield next;
  } catch(e) {
    this.status = e.status || 500;
    this.body = e.message;
  }
});

app.use(timeout);

// Some potentially slow logic:
app.use(function * () {
  yield function(done) {
    setTimeout(done, 1000);
  };
});

app.listen(3000);

License

MIT

0.1.1

9 years ago

0.1.0

10 years ago

0.0.4

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago