@azteam/express 1.2.380 → 1.2.381

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.
@@ -19,26 +19,27 @@ function _default() {
19
19
  var mTimeout = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5;
20
20
  return /*#__PURE__*/function () {
21
21
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(req, res, next) {
22
- var etag_hash;
22
+ var etagHash;
23
23
  return _regeneratorRuntime().wrap(function _callee$(_context) {
24
24
  while (1) {
25
25
  switch (_context.prev = _context.next) {
26
26
  case 0:
27
27
  if (!(req.method === 'GET')) {
28
- _context.next = 5;
28
+ _context.next = 6;
29
29
  break;
30
30
  }
31
- etag_hash = (0, _etag["default"])(req.url + floorToMinute(Math.floor(Date.now() / 1000), mTimeout));
32
- if (!(req.headers['if-none-match'] === etag_hash)) {
31
+ etagHash = (0, _etag["default"])(req.url + floorToMinute(Math.floor(Date.now() / 1000), mTimeout));
32
+ if (!(req.headers['if-none-match'] === etagHash)) {
33
33
  _context.next = 4;
34
34
  break;
35
35
  }
36
36
  return _context.abrupt("return", res.status(304).send());
37
37
  case 4:
38
- res.setHeader('ETag', etag_hash);
39
- case 5:
40
- return _context.abrupt("return", next());
38
+ res.setHeader('ETag', etagHash);
39
+ res.setHeader('Cache-Control', "max-age=".concat(mTimeout * 60));
41
40
  case 6:
41
+ return _context.abrupt("return", next());
42
+ case 7:
42
43
  case "end":
43
44
  return _context.stop();
44
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.380",
3
+ "version": "1.2.381",
4
4
  "license": "MIT",
5
5
  "author": "toda <sp.azsolution.net@gmail.com>",
6
6
  "main": "./lib/index.js",
@@ -2,18 +2,18 @@ import etag from 'etag';
2
2
 
3
3
  function floorToMinute(time, minutes) {
4
4
  const roundSecond = minutes * 60;
5
- time = time - (time % (Math.floor(time / roundSecond) * roundSecond));
6
- return time;
5
+ return time - (time % (Math.floor(time / roundSecond) * roundSecond));
7
6
  }
8
7
 
9
8
  export default function (mTimeout = 5) {
10
9
  return async function (req, res, next) {
11
10
  if (req.method === 'GET') {
12
- const etag_hash = etag(req.url + floorToMinute(Math.floor(Date.now() / 1000), mTimeout));
13
- if (req.headers['if-none-match'] === etag_hash) {
11
+ const etagHash = etag(req.url + floorToMinute(Math.floor(Date.now() / 1000), mTimeout));
12
+ if (req.headers['if-none-match'] === etagHash) {
14
13
  return res.status(304).send();
15
14
  }
16
- res.setHeader('ETag', etag_hash);
15
+ res.setHeader('ETag', etagHash);
16
+ res.setHeader('Cache-Control', `max-age=${mTimeout * 60}`);
17
17
  }
18
18
  return next();
19
19
  };