@azteam/express 1.2.284 → 1.2.285

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
@@ -62,55 +62,36 @@ var Server = /*#__PURE__*/function () {
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
64
  _classCallCheck(this, Server);
65
- this.redis = null;
66
65
  this.options = _objectSpread({
67
- isAllowEmptyOrigin: true
66
+ redis: null,
67
+ isAllowEmptyOrigin: true,
68
+ whiteList: [],
69
+ cookieOption: {},
70
+ debug: process.env.NODE_ENV === 'development'
68
71
  }, options);
69
- this.cookieOption = {
72
+ this.redis = this.options.redis;
73
+ this.isAllowEmptyOrigin = this.options.isAllowEmptyOrigin;
74
+ this.whiteList = this.options.whiteList;
75
+ this.debug = this.options.debug;
76
+ this.cookieOption = _objectSpread({
70
77
  domain: null,
71
78
  path: '/',
72
79
  secure: process.env.NODE_ENV !== 'development',
73
80
  httpOnly: true,
74
81
  signed: true,
75
82
  sameSite: 'Lax'
76
- };
83
+ }, this.options.cookieOption);
77
84
  this.middlewares = [];
78
85
  this.controllers = [];
79
- this.whiteList = [];
80
- this.debug = process.env.NODE_ENV === 'development';
81
86
  this.initController(currentDir);
82
87
  }
83
88
  _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
89
  key: "setCallbackError",
97
90
  value: function setCallbackError() {
98
91
  var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
99
92
  this.callbackError = callback;
100
93
  return this;
101
94
  }
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
95
  }, {
115
96
  key: "addController",
116
97
  value: function addController(name, version, controller) {
@@ -155,7 +136,7 @@ var Server = /*#__PURE__*/function () {
155
136
  if (!_lodash["default"].isEmpty(this.controllers)) {
156
137
  var WHITE_LIST = this.whiteList;
157
138
  var COOKIE_OPTION = this.cookieOption;
158
- var isAllowEmptyOrigin = this.options.isAllowEmptyOrigin;
139
+ var IS_ALLOW_EMPTY = this.isAllowEmptyOrigin;
159
140
  var app = (0, _express["default"])();
160
141
  app.use((0, _helmet["default"])({
161
142
  frameguard: false
@@ -178,7 +159,7 @@ var Server = /*#__PURE__*/function () {
178
159
  var error = null;
179
160
  if (!authorization && !appSecret && !agent.startsWith('toda')) {
180
161
  if (!origin) {
181
- if (!isAllowEmptyOrigin) {
162
+ if (!IS_ALLOW_EMPTY) {
182
163
  error = new _error.ErrorException(_error.CORS, "Not allowed by CORS");
183
164
  }
184
165
  } 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.285",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./src/index.js",
6
6
  "scripts": {
package/src/Server.js CHANGED
@@ -41,12 +41,20 @@ function omitItem(item, guard, allow) {
41
41
 
42
42
  class Server {
43
43
  constructor(currentDir = '', options = {}) {
44
- this.redis = 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,44 +62,20 @@ 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
72
  }
66
73
 
67
- setRedis(redis) {
68
- this.redis = redis;
69
- return this;
70
- }
71
-
72
- setCookieOption(cookieOption) {
73
- this.cookieOption = {
74
- ...this.cookieOption,
75
- ...cookieOption,
76
- };
77
- return this;
78
- }
79
-
80
74
  setCallbackError(callback = null) {
81
75
  this.callbackError = callback;
82
76
  return this;
83
77
  }
84
78
 
85
- setWhiteList(whiteList) {
86
- this.whiteList = whiteList;
87
- return this;
88
- }
89
-
90
- setDebug(debug) {
91
- this.debug = debug;
92
- return this;
93
- }
94
-
95
79
  addController(name, version, controller) {
96
80
  this.controllers.push({
97
81
  name,
@@ -132,7 +116,7 @@ class Server {
132
116
  if (!_.isEmpty(this.controllers)) {
133
117
  const WHITE_LIST = this.whiteList;
134
118
  const COOKIE_OPTION = this.cookieOption;
135
- const {isAllowEmptyOrigin} = this.options;
119
+ const IS_ALLOW_EMPTY = this.isAllowEmptyOrigin;
136
120
 
137
121
  const app = express();
138
122
  app.use(
@@ -159,7 +143,7 @@ class Server {
159
143
  let error = null;
160
144
  if (!authorization && !appSecret && !agent.startsWith('toda')) {
161
145
  if (!origin) {
162
- if (!isAllowEmptyOrigin) {
146
+ if (!IS_ALLOW_EMPTY) {
163
147
  error = new ErrorException(CORS, `Not allowed by CORS`);
164
148
  }
165
149
  } else if (!WHITE_LIST.some((re) => origin.endsWith(re))) {