A Koa middleware to handle requests timeouts
How it works | Install | Usage
koa-timeout-middleware
uses
Promise.race
to race a setTimeout
against your Koa middlewares/response.
The middleware is available on npm
# npm install
npm install --save koa-timeout-middleware
# yarn install
yarn add koa-timeout-middleware
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