Skip to content

h1b9b/koa-timeout

Repository files navigation

Koa Timeout Middleware

A Koa middleware to handle requests timeouts

How it works | Install | Usage

How it works

koa-timeout-middleware uses Promise.race to race a setTimeout against your Koa middlewares/response.

Installation

The middleware is available on npm

# npm install
npm install --save koa-timeout-middleware
# yarn install
yarn add koa-timeout-middleware

Usage

The middleware can be configured with a custom timeout time and status code.

import Koa from 'koa'
import { timeout } from 'koa-timeout-middleware'

const app = new Koa()

app.use(timeout(1000))                     // 1s timeout
app.use(timeout(1000, { status: 499 }))    // 1s timeout with 499 status

About

A Koa middleware to handle requests timeouts

Resources

License

Stars

Watchers

Forks

Packages

No packages published