@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
|
|
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 =
|
|
28
|
+
_context.next = 6;
|
|
29
29
|
break;
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
if (!(req.headers['if-none-match'] ===
|
|
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',
|
|
39
|
-
|
|
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
|
@@ -2,18 +2,18 @@ import etag from 'etag';
|
|
|
2
2
|
|
|
3
3
|
function floorToMinute(time, minutes) {
|
|
4
4
|
const roundSecond = minutes * 60;
|
|
5
|
-
|
|
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
|
|
13
|
-
if (req.headers['if-none-match'] ===
|
|
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',
|
|
15
|
+
res.setHeader('ETag', etagHash);
|
|
16
|
+
res.setHeader('Cache-Control', `max-age=${mTimeout * 60}`);
|
|
17
17
|
}
|
|
18
18
|
return next();
|
|
19
19
|
};
|