@azteam/express 1.2.343 → 1.2.344

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
@@ -94,10 +94,9 @@ var Server = /*#__PURE__*/function () {
94
94
  if (_fs["default"].statSync("".concat(apiDir, "/").concat(dirName)).isDirectory()) {
95
95
  var versionDirs = _fs["default"].readdirSync("".concat(apiDir, "/").concat(dirName));
96
96
  for (var j = 0; j < versionDirs.length; j += 1) {
97
- var versionName = versionDirs[j];
98
-
99
- // eslint-disable-next-line global-require,import/no-dynamic-require
100
- var controller = require("".concat(apiDir, "/").concat(dirName, "/").concat(versionName, "/controller"))["default"];
97
+ var versionName = versionDirs[j],
98
+ // eslint-disable-next-line global-require,import/no-dynamic-require
99
+ controller = require("".concat(apiDir, "/").concat(dirName, "/").concat(versionName, "/controller"))["default"];
101
100
  this.addController(dirName, versionName, controller);
102
101
  }
103
102
  }
@@ -116,10 +115,10 @@ var Server = /*#__PURE__*/function () {
116
115
  value: function startAPI(port) {
117
116
  var _this4 = this;
118
117
  if (!_lodash["default"].isEmpty(this.controllers)) {
119
- var WHITE_LIST = this.whiteList;
120
- var COOKIE_OPTION = this.cookieOption;
121
- var IS_ALLOW_EMPTY = this.isAllowEmptyOrigin;
122
- var app = (0, _express["default"])();
118
+ var WHITE_LIST = this.whiteList,
119
+ COOKIE_OPTION = this.cookieOption,
120
+ IS_ALLOW_EMPTY = this.isAllowEmptyOrigin,
121
+ app = (0, _express["default"])();
123
122
  app.use((0, _helmet["default"])({
124
123
  frameguard: false
125
124
  }));
@@ -134,9 +133,9 @@ var Server = /*#__PURE__*/function () {
134
133
  app.set('trust proxy', 1);
135
134
  app.use((0, _cookieParser["default"])(process.env.SECRET_KEY));
136
135
  app.use((0, _cors["default"])(function (req, callback) {
137
- var origin = req.header('Origin');
138
- var authorization = req.header('Authorization');
139
- var agent = req.header('User-Agent');
136
+ var origin = req.header('Origin'),
137
+ authorization = req.header('Authorization'),
138
+ agent = req.header('User-Agent');
140
139
  var error = null;
141
140
  if (!authorization && !agent.startsWith('toda')) {
142
141
  if (!origin) {
@@ -255,7 +254,7 @@ var Server = /*#__PURE__*/function () {
255
254
  app.use(function (req, res, next) {
256
255
  delete res.cache;
257
256
  var origin = req.get('Origin');
258
- req.rootOrigin = origin ? _psl["default"].parse(origin).domain : null;
257
+ req.rootOrigin = origin ? _psl["default"].parse(origin.replace(/(?:[\0-\t\x0B\f\x0E-\u2027\u202A-\uD7FF\uE000-\uFFFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF])*\/\//, '')).domain : null;
259
258
  req.trackDevice = {
260
259
  ip: req.headers['x-forwarded-for'] || req.headers['x-real-ip'] || req.ip,
261
260
  device: req.get('X-DEVICE') || req.get('User-Agent'),
@@ -269,14 +268,14 @@ var Server = /*#__PURE__*/function () {
269
268
  });
270
269
  var msg = [];
271
270
  _lodash["default"].map(this.controllers, function (data) {
272
- var controller = data.controller;
273
- var controllerName = data.name;
274
- var controllerVersion = data.version;
275
- var listPublicRouter = controller.publicRouter();
271
+ var controller = data.controller,
272
+ controllerName = data.name,
273
+ controllerVersion = data.version,
274
+ listPublicRouter = controller.publicRouter();
276
275
  _lodash["default"].map(listPublicRouter, function (method) {
277
276
  var name = method.name,
278
- type = method.type;
279
- var router = controller[name]();
277
+ type = method.type,
278
+ router = controller[name]();
280
279
  if (!router.disabled) {
281
280
  router.path = "/".concat(method.path, "/").concat(router.path);
282
281
  router.path = controller.pathName ? "/".concat(controller.pathName).concat(router.path) : router.path;
@@ -293,7 +292,6 @@ var Server = /*#__PURE__*/function () {
293
292
  }
294
293
  });
295
294
  });
296
- console.table(msg);
297
295
  app.all('/', /*#__PURE__*/function () {
298
296
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(req, res) {
299
297
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
@@ -33,14 +33,15 @@ function _default(secretKey) {
33
33
  });
34
34
  case 5:
35
35
  data = _context.sent;
36
+ delete req.body.captcha;
36
37
  if (!data.success) {
37
- _context.next = 8;
38
+ _context.next = 9;
38
39
  break;
39
40
  }
40
41
  return _context.abrupt("return", next());
41
- case 8:
42
- throw new _error.ErrorException(_error.RECAPTCHA);
43
42
  case 9:
43
+ throw new _error.ErrorException(_error.RECAPTCHA);
44
+ case 10:
44
45
  case "end":
45
46
  return _context.stop();
46
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.343",
3
+ "version": "1.2.344",
4
4
  "license": "MIT",
5
5
  "author": "toda <sp.azsolution.net@gmail.com>",
6
6
  "main": "./lib/index.js",
package/src/Server.js CHANGED
@@ -76,10 +76,9 @@ class Server {
76
76
  const versionDirs = fs.readdirSync(`${apiDir}/${dirName}`);
77
77
 
78
78
  for (let j = 0; j < versionDirs.length; j += 1) {
79
- const versionName = versionDirs[j];
80
-
81
- // eslint-disable-next-line global-require,import/no-dynamic-require
82
- const controller = require(`${apiDir}/${dirName}/${versionName}/controller`).default;
79
+ const versionName = versionDirs[j],
80
+ // eslint-disable-next-line global-require,import/no-dynamic-require
81
+ controller = require(`${apiDir}/${dirName}/${versionName}/controller`).default;
83
82
  this.addController(dirName, versionName, controller);
84
83
  }
85
84
  }
@@ -95,11 +94,11 @@ class Server {
95
94
 
96
95
  startAPI(port) {
97
96
  if (!_.isEmpty(this.controllers)) {
98
- const WHITE_LIST = this.whiteList;
99
- const COOKIE_OPTION = this.cookieOption;
100
- const IS_ALLOW_EMPTY = this.isAllowEmptyOrigin;
97
+ const WHITE_LIST = this.whiteList,
98
+ COOKIE_OPTION = this.cookieOption,
99
+ IS_ALLOW_EMPTY = this.isAllowEmptyOrigin,
100
+ app = express();
101
101
 
102
- const app = express();
103
102
  app.use(
104
103
  helmet({
105
104
  frameguard: false,
@@ -116,9 +115,9 @@ class Server {
116
115
 
117
116
  app.use(
118
117
  cors(function (req, callback) {
119
- const origin = req.header('Origin');
120
- const authorization = req.header('Authorization');
121
- const agent = req.header('User-Agent');
118
+ const origin = req.header('Origin'),
119
+ authorization = req.header('Authorization'),
120
+ agent = req.header('User-Agent');
122
121
 
123
122
  let error = null;
124
123
  if (!authorization && !agent.startsWith('toda')) {
@@ -246,7 +245,7 @@ class Server {
246
245
  delete res.cache;
247
246
 
248
247
  const origin = req.get('Origin');
249
- req.rootOrigin = origin ? psl.parse(origin).domain : null;
248
+ req.rootOrigin = origin ? psl.parse(origin.replace(/.*\/\//u, '')).domain : null;
250
249
 
251
250
  req.trackDevice = {
252
251
  ip: req.headers['x-forwarded-for'] || req.headers['x-real-ip'] || req.ip,
@@ -264,16 +263,14 @@ class Server {
264
263
 
265
264
  const msg = [];
266
265
  _.map(this.controllers, (data) => {
267
- const {controller} = data;
268
- const controllerName = data.name;
269
- const controllerVersion = data.version;
270
-
271
- const listPublicRouter = controller.publicRouter();
266
+ const {controller} = data,
267
+ controllerName = data.name,
268
+ controllerVersion = data.version,
269
+ listPublicRouter = controller.publicRouter();
272
270
 
273
271
  _.map(listPublicRouter, (method) => {
274
- const {name, type} = method;
275
-
276
- const router = controller[name]();
272
+ const {name, type} = method,
273
+ router = controller[name]();
277
274
  if (!router.disabled) {
278
275
  router.path = `/${method.path}/${router.path}`;
279
276
  router.path = controller.pathName ? `/${controller.pathName}${router.path}` : router.path;
@@ -292,8 +289,6 @@ class Server {
292
289
  });
293
290
  });
294
291
 
295
- console.table(msg);
296
-
297
292
  app.all('/', async function (req, res) {
298
293
  return res.success('welcome');
299
294
  });
@@ -7,17 +7,15 @@ export default function (secretKey) {
7
7
  throw new ErrorException(MISSING_PARAM, `field captcha is missing`);
8
8
  }
9
9
 
10
- const client = new HttpClient();
11
-
12
- const data = await client.post('https://www.google.com/recaptcha/api/siteverify', {
13
- secret: secretKey,
14
- response: req.body.captcha,
15
- });
16
-
10
+ const client = new HttpClient(),
11
+ data = await client.post('https://www.google.com/recaptcha/api/siteverify', {
12
+ secret: secretKey,
13
+ response: req.body.captcha,
14
+ });
15
+ delete req.body.captcha;
17
16
  if (data.success) {
18
17
  return next();
19
18
  }
20
-
21
19
  throw new ErrorException(RECAPTCHA);
22
20
  };
23
21
  }