@azteam/express 1.2.332 → 1.2.334

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
@@ -43,8 +43,8 @@ var RES_TYPE = {
43
43
  DOCS: 'DOCS'
44
44
  };
45
45
  var Server = /*#__PURE__*/function () {
46
- function Server() {
47
- var currentDir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
46
+ function Server(controllerDirs) {
47
+ var _this = this;
48
48
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
49
49
  var errorCallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
50
50
  _classCallCheck(this, Server);
@@ -69,7 +69,9 @@ var Server = /*#__PURE__*/function () {
69
69
  }, this.options.cookieOption);
70
70
  this.middlewares = [];
71
71
  this.controllers = [];
72
- this.initController(currentDir);
72
+ controllerDirs.map(function (dir) {
73
+ _this.initController(dir);
74
+ });
73
75
  this.callbackError = errorCallback;
74
76
  }
75
77
  _createClass(Server, [{
@@ -112,7 +114,7 @@ var Server = /*#__PURE__*/function () {
112
114
  }, {
113
115
  key: "startAPI",
114
116
  value: function startAPI(port) {
115
- var _this3 = this;
117
+ var _this4 = this;
116
118
  if (!_lodash["default"].isEmpty(this.controllers)) {
117
119
  var WHITE_LIST = this.whiteList;
118
120
  var COOKIE_OPTION = this.cookieOption;
@@ -233,18 +235,18 @@ var Server = /*#__PURE__*/function () {
233
235
  return this.json(resData);
234
236
  };
235
237
  app.response.cleanCookie = function (data) {
236
- var _this = this;
238
+ var _this2 = this;
237
239
  _lodash["default"].map(data, function (name) {
238
- _this.clearCookie(name, {
240
+ _this2.clearCookie(name, {
239
241
  domain: COOKIE_OPTION.domain
240
242
  });
241
243
  });
242
244
  };
243
245
  app.response.addCookie = function (data) {
244
- var _this2 = this;
246
+ var _this3 = this;
245
247
  _lodash["default"].map(data, function (value, key) {
246
248
  var maxAge = 86400000 * 365; // 1 year
247
- _this2.cookie(key, value, _objectSpread(_objectSpread({}, COOKIE_OPTION), {}, {
249
+ _this3.cookie(key, value, _objectSpread(_objectSpread({}, COOKIE_OPTION), {}, {
248
250
  maxAge: maxAge,
249
251
  expires: new Date(Date.now() + maxAge)
250
252
  }));
@@ -341,8 +343,8 @@ var Server = /*#__PURE__*/function () {
341
343
  } else if (error.errors[0].code === _error.UNKNOWN) {
342
344
  console.error(req.originalUrl, err);
343
345
  }
344
- if (_this3.callbackError) {
345
- _this3.callbackError(error, req.originalUrl);
346
+ if (_this4.callbackError) {
347
+ _this4.callbackError(error, req.originalUrl);
346
348
  }
347
349
  return res.status(error.status).json({
348
350
  success: false,
@@ -351,7 +353,7 @@ var Server = /*#__PURE__*/function () {
351
353
  });
352
354
  var server = _http["default"].Server(app);
353
355
  server.on('listening', function () {
354
- _this3._alert('listening', "Server start at http://localhost:".concat(server.address().port));
356
+ _this4._alert('listening', "Server start at http://localhost:".concat(server.address().port));
355
357
  });
356
358
  server.on('error', function (error) {
357
359
  if (error.syscall !== 'listen') {
@@ -360,11 +362,11 @@ var Server = /*#__PURE__*/function () {
360
362
  var bind = typeof port === 'string' ? "Pipe ".concat(port) : "Port ".concat(port);
361
363
  switch (error.code) {
362
364
  case 'EACCES':
363
- _this3._alert('EACCES', "".concat(bind, " requires elevated privileges"));
365
+ _this4._alert('EACCES', "".concat(bind, " requires elevated privileges"));
364
366
  process.exit(1);
365
367
  break;
366
368
  case 'EADDRINUSE':
367
- _this3._alert('EACCES', "".concat(bind, " is already in use"));
369
+ _this4._alert('EACCES', "".concat(bind, " is already in use"));
368
370
  process.exit(1);
369
371
  break;
370
372
  default:
@@ -29,7 +29,7 @@ function _default(key) {
29
29
  case 0:
30
30
  redis = req.redis;
31
31
  if (!redis) {
32
- _context.next = 16;
32
+ _context.next = 18;
33
33
  break;
34
34
  }
35
35
  cacheKey = key;
@@ -55,18 +55,27 @@ function _default(key) {
55
55
  case 12:
56
56
  cacheData = _context.sent;
57
57
  if (!cacheData) {
58
- _context.next = 15;
58
+ _context.next = 17;
59
+ break;
60
+ }
61
+ if (cacheData.success) {
62
+ _context.next = 16;
59
63
  break;
60
64
  }
65
+ return _context.abrupt("return", res.json({
66
+ success: true,
67
+ data: cacheData
68
+ }));
69
+ case 16:
61
70
  return _context.abrupt("return", res.json(cacheData));
62
- case 15:
71
+ case 17:
63
72
  res.cache = {
64
73
  key: cacheKey,
65
74
  ttl: options.ttl
66
75
  };
67
- case 16:
76
+ case 18:
68
77
  return _context.abrupt("return", next());
69
- case 17:
78
+ case 19:
70
79
  case "end":
71
80
  return _context.stop();
72
81
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.332",
3
+ "version": "1.2.334",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./src/index.js",
6
6
  "scripts": {
package/src/Server.js CHANGED
@@ -22,7 +22,7 @@ const RES_TYPE = {
22
22
  };
23
23
 
24
24
  class Server {
25
- constructor(currentDir = '', options = {}, errorCallback = null) {
25
+ constructor(controllerDirs, options = {}, errorCallback = null) {
26
26
  this.options = {
27
27
  redis: null,
28
28
  isAllowEmptyOrigin: true,
@@ -50,7 +50,9 @@ class Server {
50
50
  this.middlewares = [];
51
51
  this.controllers = [];
52
52
 
53
- this.initController(currentDir);
53
+ controllerDirs.map((dir) => {
54
+ this.initController(dir);
55
+ });
54
56
 
55
57
  this.callbackError = errorCallback;
56
58
  }
@@ -25,6 +25,10 @@ export default function (key, options = {}) {
25
25
  }
26
26
  const cacheData = await redis.get(cacheKey);
27
27
  if (cacheData) {
28
+ if (!cacheData.success) {
29
+ return res.json({success: true, data: cacheData});
30
+ }
31
+
28
32
  return res.json(cacheData);
29
33
  }
30
34
  res.cache = {