@azteam/express 1.2.379 → 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.
package/lib/Server.js CHANGED
@@ -52,7 +52,6 @@ var Server = /*#__PURE__*/function () {
52
52
  _classCallCheck(this, Server);
53
53
  this.options = _objectSpread({
54
54
  redis: null,
55
- isAllowEmptyOrigin: true,
56
55
  whiteList: null,
57
56
  cookieOption: {},
58
57
  debug: process.env.NODE_ENV === 'development',
@@ -60,7 +59,6 @@ var Server = /*#__PURE__*/function () {
60
59
  }, options);
61
60
  this.systemUser = this.options.systemUser;
62
61
  this.redis = this.options.redis;
63
- this.isAllowEmptyOrigin = this.options.isAllowEmptyOrigin;
64
62
  this.whiteList = this.options.whiteList;
65
63
  this.debug = this.options.debug;
66
64
  this.cookieOption = _objectSpread({
@@ -115,7 +113,6 @@ var Server = /*#__PURE__*/function () {
115
113
  if (!_lodash["default"].isEmpty(this.controllers)) {
116
114
  var WHITE_LIST = this.whiteList,
117
115
  COOKIE_OPTION = this.cookieOption,
118
- IS_ALLOW_EMPTY = this.isAllowEmptyOrigin,
119
116
  SYSTEM_USER = this.systemUser,
120
117
  app = (0, _express["default"])();
121
118
  app.use((0, _helmet["default"])({
@@ -137,11 +134,7 @@ var Server = /*#__PURE__*/function () {
137
134
  agent = req.header('User-Agent');
138
135
  var error = null;
139
136
  if (!authorization && !agent.startsWith(SYSTEM_USER)) {
140
- if (!origin) {
141
- if (!IS_ALLOW_EMPTY) {
142
- error = new _error.ErrorException(_error.CORS, "Not allowed by CORS");
143
- }
144
- } else if (WHITE_LIST && !WHITE_LIST.some(function (re) {
137
+ if (origin && WHITE_LIST && !WHITE_LIST.some(function (re) {
145
138
  return origin.endsWith(re);
146
139
  })) {
147
140
  error = new _error.ErrorException(_error.CORS, "".concat(origin, " Not allowed by CORS"));
@@ -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.379",
3
+ "version": "1.2.381",
4
4
  "license": "MIT",
5
5
  "author": "toda <sp.azsolution.net@gmail.com>",
6
6
  "main": "./lib/index.js",
package/src/Server.js CHANGED
@@ -25,7 +25,6 @@ class Server {
25
25
  constructor(serviceDirs, options = {}, errorCallback = null) {
26
26
  this.options = {
27
27
  redis: null,
28
- isAllowEmptyOrigin: true,
29
28
  whiteList: null,
30
29
  cookieOption: {},
31
30
  debug: process.env.NODE_ENV === 'development',
@@ -36,7 +35,6 @@ class Server {
36
35
  this.systemUser = this.options.systemUser;
37
36
 
38
37
  this.redis = this.options.redis;
39
- this.isAllowEmptyOrigin = this.options.isAllowEmptyOrigin;
40
38
  this.whiteList = this.options.whiteList;
41
39
  this.debug = this.options.debug;
42
40
 
@@ -94,7 +92,6 @@ class Server {
94
92
  if (!_.isEmpty(this.controllers)) {
95
93
  const WHITE_LIST = this.whiteList,
96
94
  COOKIE_OPTION = this.cookieOption,
97
- IS_ALLOW_EMPTY = this.isAllowEmptyOrigin,
98
95
  SYSTEM_USER = this.systemUser,
99
96
  app = express();
100
97
 
@@ -120,11 +117,7 @@ class Server {
120
117
 
121
118
  let error = null;
122
119
  if (!authorization && !agent.startsWith(SYSTEM_USER)) {
123
- if (!origin) {
124
- if (!IS_ALLOW_EMPTY) {
125
- error = new ErrorException(CORS, `Not allowed by CORS`);
126
- }
127
- } else if (WHITE_LIST && !WHITE_LIST.some((re) => origin.endsWith(re))) {
120
+ if (origin && WHITE_LIST && !WHITE_LIST.some((re) => origin.endsWith(re))) {
128
121
  error = new ErrorException(CORS, `${origin} Not allowed by CORS`);
129
122
  }
130
123
  }
@@ -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
  };