2.1.0 • Published 3 years ago

koajs-nocache v2.1.0

Weekly downloads
83
License
MIT
Repository
github
Last release
3 years ago

koajs-nocache

Build Status

NPM

Introduction

A node koajs middleware which add no-cache related headers for all the koajs response to disable caches. It is useful for REST API response, add no-cache headers to avoid browsers cache request response. Only GET response have no-cache headers by default.

The following headers are added to response header:

Cache-Control: no-cache, no-store, must-revalidate, proxy-revalidate
Expires: 0
Pragma: no-cache
Surrogate-Control: no-store

Install

npm install koajs-nocache

API

nocache(options):

/**
 * nocache middleware.
 *
 * @param {Object} [options]
 *                 - {String|Array} methods need add nocache headers.
 *                                  default is ['GET']
 *
 * @return {Function} nocache middleware
 */

Usage

Add no-cache related headers to all the GET responses:

const nocache = require('koajs-nocache');

app = new Koa();
app.use(nocache());

or use you can only add no-cache headers to specific requests with koa-router:

const nocache = require('koajs-nocache');

router.get('/foo',
           nocache(),
           function(ctx, next) {
    ctx.body = ...;
});

Checkout test/nocache_test.js for example usages.

License

MIT

2.1.0

3 years ago

2.0.3

4 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago