@azteam/express 1.2.378 → 1.2.380

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"));
@@ -124,26 +124,26 @@ var SocketServer = /*#__PURE__*/function () {
124
124
  value: function startPort(port) {
125
125
  var _this = this;
126
126
  if (!_lodash["default"].isEmpty(this.controllers)) {
127
- var WHITE_LIST = this.whiteList;
128
- var server = _http["default"].Server((0, _express["default"])());
129
- var io = (0, _socket["default"])(server, {
130
- wsEngine: 'eiows',
131
- perMessageDeflate: {
132
- threshold: 32768
133
- },
134
- cors: {
135
- credentials: true,
136
- origin: function origin(_origin, callback) {
137
- if (!_origin || !WHITE_LIST.length || WHITE_LIST.some(function (re) {
138
- return _origin.endsWith(re);
139
- })) {
140
- callback(null, true);
141
- } else {
142
- callback(new Error("".concat(_origin, " Not allowed by CORS")));
127
+ var WHITE_LIST = this.whiteList,
128
+ server = _http["default"].Server((0, _express["default"])()),
129
+ io = (0, _socket["default"])(server, {
130
+ wsEngine: 'eiows',
131
+ perMessageDeflate: {
132
+ threshold: 32768
133
+ },
134
+ cors: {
135
+ credentials: true,
136
+ origin: function origin(_origin, callback) {
137
+ if (!_origin || !WHITE_LIST.length || WHITE_LIST.some(function (re) {
138
+ return _origin.endsWith(re);
139
+ })) {
140
+ callback(null, true);
141
+ } else {
142
+ callback(new Error("".concat(_origin, " Not allowed by CORS")));
143
+ }
143
144
  }
144
145
  }
145
- }
146
- });
146
+ });
147
147
  if (this.options.redisConfig) {
148
148
  io.adapter((0, _redisAdapter.createAdapter)(this.options.redisConfig));
149
149
  }
@@ -152,8 +152,8 @@ var SocketServer = /*#__PURE__*/function () {
152
152
  var controller = obj.controller;
153
153
  _lodash["default"].map(controller, function (item, key) {
154
154
  item.path = obj.version.startsWith('v') ? "/".concat(obj.version).concat(item.path) : item.path;
155
- var nsp = io.of(item.path);
156
- var middlewares = [].concat(_toConsumableArray(_this.middlewares), _toConsumableArray(item.middlewares || []));
155
+ var nsp = io.of(item.path),
156
+ middlewares = [].concat(_toConsumableArray(_this.middlewares), _toConsumableArray(item.middlewares || []));
157
157
  nsp.use(wrap(_bodyParser["default"].urlencoded({
158
158
  limit: '5mb',
159
159
  extended: true
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.378",
3
+ "version": "1.2.380",
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
  }
@@ -73,26 +73,24 @@ class SocketServer {
73
73
 
74
74
  startPort(port) {
75
75
  if (!_.isEmpty(this.controllers)) {
76
- const WHITE_LIST = this.whiteList;
77
-
78
- const server = http.Server(express());
79
-
80
- const io = socketIO(server, {
81
- wsEngine: 'eiows',
82
- perMessageDeflate: {
83
- threshold: 32768,
84
- },
85
- cors: {
86
- credentials: true,
87
- origin(origin, callback) {
88
- if (!origin || !WHITE_LIST.length || WHITE_LIST.some((re) => origin.endsWith(re))) {
89
- callback(null, true);
90
- } else {
91
- callback(new Error(`${origin} Not allowed by CORS`));
92
- }
76
+ const WHITE_LIST = this.whiteList,
77
+ server = http.Server(express()),
78
+ io = socketIO(server, {
79
+ wsEngine: 'eiows',
80
+ perMessageDeflate: {
81
+ threshold: 32768,
93
82
  },
94
- },
95
- });
83
+ cors: {
84
+ credentials: true,
85
+ origin(origin, callback) {
86
+ if (!origin || !WHITE_LIST.length || WHITE_LIST.some((re) => origin.endsWith(re))) {
87
+ callback(null, true);
88
+ } else {
89
+ callback(new Error(`${origin} Not allowed by CORS`));
90
+ }
91
+ },
92
+ },
93
+ });
96
94
 
97
95
  if (this.options.redisConfig) {
98
96
  io.adapter(createAdapter(this.options.redisConfig));
@@ -105,9 +103,8 @@ class SocketServer {
105
103
  _.map(controller, (item, key) => {
106
104
  item.path = obj.version.startsWith('v') ? `/${obj.version}${item.path}` : item.path;
107
105
 
108
- const nsp = io.of(item.path);
109
-
110
- const middlewares = [...this.middlewares, ...(item.middlewares || [])];
106
+ const nsp = io.of(item.path),
107
+ middlewares = [...this.middlewares, ...(item.middlewares || [])];
111
108
 
112
109
  nsp.use(wrap(bodyParser.urlencoded({limit: '5mb', extended: true})));
113
110
  nsp.use(wrap(bodyParser.json({limit: '5mb'})));