koajs-nocache
TypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i koajs-nocache

Weekly Downloads

338

Version

2.1.0

License

MIT

Unpacked Size

4.17 kB

Total Files

5

Last publish

Collaborators

  • mingc