tr-apisrv 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +9 -2
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -207,8 +207,15 @@ var ApiSrv = function(opts) {
207
207
  }
208
208
  r.headers = req.headers;
209
209
  r.res = res;
210
- r.jsonResponse = function(data, code) {
211
- res.writeHead(code ? code : 200, { 'Content-Type': 'application/json; charset=utf-8' });
210
+ r.jsonResponse = function(data, code, excludeNoCacheHeaders) {
211
+ var headers = { 'Content-Type': 'application/json; charset=utf-8' };
212
+ if (! excludeNoCacheHeaders) {
213
+ headers = Object.assign(headers,
214
+ { 'Cache-Control': 'no-store, no-cache, must-revalidate, post-check=0, pre-check=0',
215
+ 'Expires': 'Wed, 01 Jan 2020 12:00:00 GMT',
216
+ 'Pragma': 'no-cache' });
217
+ }
218
+ res.writeHead(code ? code : 200, headers);
212
219
  if (this.prettyPrintJsonResponses) {
213
220
  res.write(JSON.stringify(data, null, 2));
214
221
  res.write("\n");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tr-apisrv",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "description": "A simple asynchronous API server class",
5
5
  "main": "index.js",
6
6
  "scripts": {