https://github.com/mingchen/koajs-nocache
Add nocache related headers to koajs response.
https://github.com/mingchen/koajs-nocache
Last synced: 4 months ago
JSON representation
Add nocache related headers to koajs response.
- Host: GitHub
- URL: https://github.com/mingchen/koajs-nocache
- Owner: mingchen
- License: mit
- Created: 2019-01-12T04:16:15.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-11-11T19:50:29.000Z (over 5 years ago)
- Last Synced: 2025-08-09T09:37:41.013Z (11 months ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# koajs-nocache
[](https://travis-ci.org/mingchen/koajs-nocache)
[](https://nodei.co/npm/koajs-nocache/)
## 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](LICENSE.txt)