@azteam/express 1.2.333 → 1.2.335

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(serviceDirs) {
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
+ serviceDirs.map(function (dir) {
73
+ _this.initController(dir);
74
+ });
73
75
  this.callbackError = errorCallback;
74
76
  }
75
77
  _createClass(Server, [{
@@ -85,7 +87,7 @@ var Server = /*#__PURE__*/function () {
85
87
  }, {
86
88
  key: "initController",
87
89
  value: function initController(apiDir) {
88
- if (apiDir) {
90
+ if (_fs["default"].existsSync(apiDir)) {
89
91
  var controllerDirs = _fs["default"].readdirSync(apiDir);
90
92
  for (var i = 0; i < controllerDirs.length; i += 1) {
91
93
  var dirName = controllerDirs[i];
@@ -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:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.333",
3
+ "version": "1.2.335",
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(serviceDirs, 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
+ serviceDirs.map((dir) => {
54
+ this.initController(dir);
55
+ });
54
56
 
55
57
  this.callbackError = errorCallback;
56
58
  }
@@ -65,7 +67,7 @@ class Server {
65
67
  }
66
68
 
67
69
  initController(apiDir) {
68
- if (apiDir) {
70
+ if (fs.existsSync(apiDir)) {
69
71
  const controllerDirs = fs.readdirSync(apiDir);
70
72
 
71
73
  for (let i = 0; i < controllerDirs.length; i += 1) {