@azteam/express 1.2.342 → 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
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
139
|
-
|
|
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
|
-
|
|
274
|
-
|
|
275
|
-
|
|
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
|
-
|
|
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) {
|
|
@@ -23,6 +23,7 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
|
|
|
23
23
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
24
24
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
25
25
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
26
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
26
27
|
var TEMPLATE_DIR = _path["default"].join(__dirname, '..', '..', 'template/sitemap');
|
|
27
28
|
var SitemapController = /*#__PURE__*/function (_Controller) {
|
|
28
29
|
_inherits(SitemapController, _Controller);
|
|
@@ -32,6 +33,7 @@ var SitemapController = /*#__PURE__*/function (_Controller) {
|
|
|
32
33
|
var pathName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
|
33
34
|
_classCallCheck(this, SitemapController);
|
|
34
35
|
_this = _super.call(this, repository, pathName);
|
|
36
|
+
_defineProperty(_assertThisInitialized(_this), "select", 'slug modified_at');
|
|
35
37
|
_this.sitemapName = _lodash["default"].camelCase(_this.name);
|
|
36
38
|
return _this;
|
|
37
39
|
}
|
|
@@ -63,7 +65,7 @@ var SitemapController = /*#__PURE__*/function (_Controller) {
|
|
|
63
65
|
domains: req.rootOrigin,
|
|
64
66
|
metadata_disable: 0
|
|
65
67
|
}, {
|
|
66
|
-
select:
|
|
68
|
+
select: _this2.select,
|
|
67
69
|
page: page,
|
|
68
70
|
limit: 1000
|
|
69
71
|
});
|
|
@@ -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 =
|
|
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
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
|
-
|
|
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
|
-
|
|
100
|
-
|
|
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
|
-
|
|
121
|
-
|
|
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
|
-
|
|
269
|
-
|
|
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,6 +7,8 @@ import Controller from './Controller';
|
|
|
7
7
|
const TEMPLATE_DIR = path.join(__dirname, '..', '..', 'template/sitemap');
|
|
8
8
|
|
|
9
9
|
class SitemapController extends Controller {
|
|
10
|
+
select = 'slug modified_at';
|
|
11
|
+
|
|
10
12
|
constructor(repository, pathName = null) {
|
|
11
13
|
super(repository, pathName);
|
|
12
14
|
this.sitemapName = _.camelCase(this.name);
|
|
@@ -29,7 +31,7 @@ class SitemapController extends Controller {
|
|
|
29
31
|
metadata_disable: 0,
|
|
30
32
|
},
|
|
31
33
|
{
|
|
32
|
-
select:
|
|
34
|
+
select: this.select,
|
|
33
35
|
page,
|
|
34
36
|
limit: 1000,
|
|
35
37
|
}
|
|
@@ -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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
}
|