@azteam/express 1.2.322 → 1.2.325

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
@@ -51,7 +51,7 @@ var Server = /*#__PURE__*/function () {
51
51
  this.options = _objectSpread({
52
52
  redis: null,
53
53
  isAllowEmptyOrigin: true,
54
- whiteList: [],
54
+ whiteList: null,
55
55
  cookieOption: {},
56
56
  debug: process.env.NODE_ENV === 'development'
57
57
  }, options);
@@ -131,32 +131,28 @@ var Server = /*#__PURE__*/function () {
131
131
  }));
132
132
  app.set('trust proxy', 1);
133
133
  app.use((0, _cookieParser["default"])(process.env.SECRET_KEY));
134
-
135
- // app.use(
136
- // cors(function (req, callback) {
137
- // const origin = req.header('Origin');
138
- // const authorization = req.header('Authorization');
139
- // const appSecret = req.header('x-app-secret');
140
- // const agent = req.header('User-Agent');
141
- //
142
- // let error = null;
143
- // if (!authorization && !appSecret && !agent.startsWith('toda')) {
144
- // if (!origin) {
145
- // if (!IS_ALLOW_EMPTY) {
146
- // error = new ErrorException(CORS, `Not allowed by CORS`);
147
- // }
148
- // }
149
- // else if (!WHITE_LIST.some((re) => origin.endsWith(re))) {
150
- // error = new ErrorException(CORS, `${origin} Not allowed by CORS`);
151
- // }
152
- // }
153
- // callback(error, {
154
- // credentials: true,
155
- // origin: true,
156
- // });
157
- // })
158
- // );
159
-
134
+ app.use((0, _cors["default"])(function (req, callback) {
135
+ var origin = req.header('Origin');
136
+ var authorization = req.header('Authorization');
137
+ var appSecret = req.header('x-app-secret');
138
+ var agent = req.header('User-Agent');
139
+ var error = null;
140
+ if (!authorization && !appSecret && !agent.startsWith('toda')) {
141
+ if (!origin) {
142
+ if (!IS_ALLOW_EMPTY) {
143
+ error = new _error.ErrorException(_error.CORS, "Not allowed by CORS");
144
+ }
145
+ } else if (WHITE_LIST && !WHITE_LIST.some(function (re) {
146
+ return origin.endsWith(re);
147
+ })) {
148
+ error = new _error.ErrorException(_error.CORS, "".concat(origin, " Not allowed by CORS"));
149
+ }
150
+ }
151
+ callback(error, {
152
+ credentials: true,
153
+ origin: true
154
+ });
155
+ }));
160
156
  if (this.debug) {
161
157
  app.use((0, _morgan["default"])('dev'));
162
158
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.322",
3
+ "version": "1.2.325",
4
4
  "main": "./lib/index.js",
5
5
  "module": "./src/index.js",
6
6
  "scripts": {
package/src/Server.js CHANGED
@@ -26,7 +26,7 @@ class Server {
26
26
  this.options = {
27
27
  redis: null,
28
28
  isAllowEmptyOrigin: true,
29
- whiteList: [],
29
+ whiteList: null,
30
30
  cookieOption: {},
31
31
  debug: process.env.NODE_ENV === 'development',
32
32
  ...options,
@@ -112,30 +112,29 @@ class Server {
112
112
 
113
113
  app.use(cookieParser(process.env.SECRET_KEY));
114
114
 
115
- // app.use(
116
- // cors(function (req, callback) {
117
- // const origin = req.header('Origin');
118
- // const authorization = req.header('Authorization');
119
- // const appSecret = req.header('x-app-secret');
120
- // const agent = req.header('User-Agent');
121
- //
122
- // let error = null;
123
- // if (!authorization && !appSecret && !agent.startsWith('toda')) {
124
- // if (!origin) {
125
- // if (!IS_ALLOW_EMPTY) {
126
- // error = new ErrorException(CORS, `Not allowed by CORS`);
127
- // }
128
- // }
129
- // else if (!WHITE_LIST.some((re) => origin.endsWith(re))) {
130
- // error = new ErrorException(CORS, `${origin} Not allowed by CORS`);
131
- // }
132
- // }
133
- // callback(error, {
134
- // credentials: true,
135
- // origin: true,
136
- // });
137
- // })
138
- // );
115
+ app.use(
116
+ cors(function (req, callback) {
117
+ const origin = req.header('Origin');
118
+ const authorization = req.header('Authorization');
119
+ const appSecret = req.header('x-app-secret');
120
+ const agent = req.header('User-Agent');
121
+
122
+ let error = null;
123
+ if (!authorization && !appSecret && !agent.startsWith('toda')) {
124
+ if (!origin) {
125
+ if (!IS_ALLOW_EMPTY) {
126
+ error = new ErrorException(CORS, `Not allowed by CORS`);
127
+ }
128
+ } else if (WHITE_LIST && !WHITE_LIST.some((re) => origin.endsWith(re))) {
129
+ error = new ErrorException(CORS, `${origin} Not allowed by CORS`);
130
+ }
131
+ }
132
+ callback(error, {
133
+ credentials: true,
134
+ origin: true,
135
+ });
136
+ })
137
+ );
139
138
 
140
139
  if (this.debug) {
141
140
  app.use(morgan('dev'));