@azteam/express 1.2.284 → 1.2.286

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
@@ -61,57 +61,33 @@ var Server = /*#__PURE__*/function () {
61
61
  function Server() {
62
62
  var currentDir = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
63
63
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
64
+ var errorCallback = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
64
65
  _classCallCheck(this, Server);
65
- this.redis = null;
66
66
  this.options = _objectSpread({
67
- isAllowEmptyOrigin: true
67
+ redis: null,
68
+ isAllowEmptyOrigin: true,
69
+ whiteList: [],
70
+ cookieOption: {},
71
+ debug: process.env.NODE_ENV === 'development'
68
72
  }, options);
69
- this.cookieOption = {
73
+ this.redis = this.options.redis;
74
+ this.isAllowEmptyOrigin = this.options.isAllowEmptyOrigin;
75
+ this.whiteList = this.options.whiteList;
76
+ this.debug = this.options.debug;
77
+ this.cookieOption = _objectSpread({
70
78
  domain: null,
71
79
  path: '/',
72
80
  secure: process.env.NODE_ENV !== 'development',
73
81
  httpOnly: true,
74
82
  signed: true,
75
83
  sameSite: 'Lax'
76
- };
84
+ }, this.options.cookieOption);
77
85
  this.middlewares = [];
78
86
  this.controllers = [];
79
- this.whiteList = [];
80
- this.debug = process.env.NODE_ENV === 'development';
81
87
  this.initController(currentDir);
88
+ this.callbackError = errorCallback;
82
89
  }
83
90
  _createClass(Server, [{
84
- key: "setRedis",
85
- value: function setRedis(redis) {
86
- this.redis = redis;
87
- return this;
88
- }
89
- }, {
90
- key: "setCookieOption",
91
- value: function setCookieOption(cookieOption) {
92
- this.cookieOption = _objectSpread(_objectSpread({}, this.cookieOption), cookieOption);
93
- return this;
94
- }
95
- }, {
96
- key: "setCallbackError",
97
- value: function setCallbackError() {
98
- var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
99
- this.callbackError = callback;
100
- return this;
101
- }
102
- }, {
103
- key: "setWhiteList",
104
- value: function setWhiteList(whiteList) {
105
- this.whiteList = whiteList;
106
- return this;
107
- }
108
- }, {
109
- key: "setDebug",
110
- value: function setDebug(debug) {
111
- this.debug = debug;
112
- return this;
113
- }
114
- }, {
115
91
  key: "addController",
116
92
  value: function addController(name, version, controller) {
117
93
  this.controllers.push({
@@ -155,7 +131,7 @@ var Server = /*#__PURE__*/function () {
155
131
  if (!_lodash["default"].isEmpty(this.controllers)) {
156
132
  var WHITE_LIST = this.whiteList;
157
133
  var COOKIE_OPTION = this.cookieOption;
158
- var isAllowEmptyOrigin = this.options.isAllowEmptyOrigin;
134
+ var IS_ALLOW_EMPTY = this.isAllowEmptyOrigin;
159
135
  var app = (0, _express["default"])();
160
136
  app.use((0, _helmet["default"])({
161
137
  frameguard: false
@@ -178,7 +154,7 @@ var Server = /*#__PURE__*/function () {
178
154
  var error = null;
179
155
  if (!authorization && !appSecret && !agent.startsWith('toda')) {
180
156
  if (!origin) {
181
- if (!isAllowEmptyOrigin) {
157
+ if (!IS_ALLOW_EMPTY) {
182
158
  error = new _error.ErrorException(_error.CORS, "Not allowed by CORS");
183
159
  }
184
160
  } else if (!WHITE_LIST.some(function (re) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.284",
3
+ "version": "1.2.286",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./src/index.js",
6
6
  "scripts": {
package/src/Server.js CHANGED
@@ -40,13 +40,21 @@ function omitItem(item, guard, allow) {
40
40
  }
41
41
 
42
42
  class Server {
43
- constructor(currentDir = '', options = {}) {
44
- this.redis = null;
43
+ constructor(currentDir = '', options = {}, errorCallback = null) {
45
44
  this.options = {
45
+ redis: null,
46
46
  isAllowEmptyOrigin: true,
47
+ whiteList: [],
48
+ cookieOption: {},
49
+ debug: process.env.NODE_ENV === 'development',
47
50
  ...options,
48
51
  };
49
52
 
53
+ this.redis = this.options.redis;
54
+ this.isAllowEmptyOrigin = this.options.isAllowEmptyOrigin;
55
+ this.whiteList = this.options.whiteList;
56
+ this.debug = this.options.debug;
57
+
50
58
  this.cookieOption = {
51
59
  domain: null,
52
60
  path: '/',
@@ -54,42 +62,15 @@ class Server {
54
62
  httpOnly: true,
55
63
  signed: true,
56
64
  sameSite: 'Lax',
65
+ ...this.options.cookieOption,
57
66
  };
58
67
 
59
68
  this.middlewares = [];
60
69
  this.controllers = [];
61
- this.whiteList = [];
62
- this.debug = process.env.NODE_ENV === 'development';
63
70
 
64
71
  this.initController(currentDir);
65
- }
66
-
67
- setRedis(redis) {
68
- this.redis = redis;
69
- return this;
70
- }
71
72
 
72
- setCookieOption(cookieOption) {
73
- this.cookieOption = {
74
- ...this.cookieOption,
75
- ...cookieOption,
76
- };
77
- return this;
78
- }
79
-
80
- setCallbackError(callback = null) {
81
- this.callbackError = callback;
82
- return this;
83
- }
84
-
85
- setWhiteList(whiteList) {
86
- this.whiteList = whiteList;
87
- return this;
88
- }
89
-
90
- setDebug(debug) {
91
- this.debug = debug;
92
- return this;
73
+ this.callbackError = errorCallback;
93
74
  }
94
75
 
95
76
  addController(name, version, controller) {
@@ -132,7 +113,7 @@ class Server {
132
113
  if (!_.isEmpty(this.controllers)) {
133
114
  const WHITE_LIST = this.whiteList;
134
115
  const COOKIE_OPTION = this.cookieOption;
135
- const {isAllowEmptyOrigin} = this.options;
116
+ const IS_ALLOW_EMPTY = this.isAllowEmptyOrigin;
136
117
 
137
118
  const app = express();
138
119
  app.use(
@@ -159,7 +140,7 @@ class Server {
159
140
  let error = null;
160
141
  if (!authorization && !appSecret && !agent.startsWith('toda')) {
161
142
  if (!origin) {
162
- if (!isAllowEmptyOrigin) {
143
+ if (!IS_ALLOW_EMPTY) {
163
144
  error = new ErrorException(CORS, `Not allowed by CORS`);
164
145
  }
165
146
  } else if (!WHITE_LIST.some((re) => origin.endsWith(re))) {