@x-9lab/xlab 1.5.4 → 1.6.0
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/@types/env.d.ts +1 -0
- package/@types/init-env.d.ts +1 -0
- package/@types/middleware/compress.d.ts +2 -1
- package/@types/server.d.ts +2 -0
- package/dist/@config/config.dev.js +3 -5
- package/dist/@config/config.js +3 -5
- package/dist/@config/config.sand.js +3 -5
- package/dist/bin/watch.js +5 -5
- package/dist/cluster.js +33 -53
- package/dist/components/assets/index.js +4 -6
- package/dist/components/cluster/index.js +4 -11
- package/dist/components/common/index.js +46 -33
- package/dist/components/cron/index.js +14 -21
- package/dist/components/header/index.js +17 -24
- package/dist/components/header/time.js +2 -4
- package/dist/components/log/index.js +6 -13
- package/dist/components/mime/index.js +2 -4
- package/dist/components/return-code/index.js +18 -25
- package/dist/components/uuid/index.js +11 -17
- package/dist/config/getEnv.js +4 -6
- package/dist/config/index.js +20 -27
- package/dist/config/process-custom-config-files.js +20 -22
- package/dist/config/process-def-config-file.js +9 -11
- package/dist/custom.js +17 -19
- package/dist/default-x-config.js +5 -7
- package/dist/dot-file.js +8 -10
- package/dist/global.js +5 -8
- package/dist/init-env.js +19 -0
- package/dist/middleware/@bin/html-filter.js +6 -13
- package/dist/middleware/bad-request.js +8 -10
- package/dist/middleware/compress.js +6 -8
- package/dist/middleware/cors.js +5 -8
- package/dist/middleware/fresh-filter.js +7 -10
- package/dist/middleware/handle-pre-dir.js +3 -5
- package/dist/middleware/request-filter.js +22 -43
- package/dist/middleware/service-mark.js +3 -6
- package/dist/middlewares.js +16 -16
- package/dist/router.js +18 -19
- package/dist/server.js +45 -67
- package/package.json +8 -8
|
@@ -2,57 +2,46 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
getReturnCode: ()=>getReturnCode,
|
|
13
|
-
getCodeDetail: ()=>getCodeDetail,
|
|
14
|
-
set: ()=>set,
|
|
15
|
-
ErrorTypes: ()=>ErrorTypes
|
|
16
|
-
});
|
|
17
|
-
const _utils = require("@x-drive/utils");
|
|
5
|
+
exports.ErrorTypes = exports.set = exports.getCodeDetail = exports.getReturnCode = void 0;
|
|
6
|
+
var _utils = require("@x-drive/utils");
|
|
18
7
|
/**
|
|
19
8
|
* 状态详细信息
|
|
20
9
|
*/ const CODE_DETAIL = {
|
|
21
10
|
"FAIL": {
|
|
22
11
|
"errorcode": -1,
|
|
23
|
-
"msg": "
|
|
12
|
+
"msg": "\u7CFB\u7EDF\u7E41\u5FD9\uFF0C\u8BF7\u7A0D\u5019\u518D\u8BD5"
|
|
24
13
|
},
|
|
25
14
|
"SUCCESS": {
|
|
26
15
|
"errorcode": 0,
|
|
27
|
-
"msg": "
|
|
16
|
+
"msg": "\u8BF7\u6C42\u6210\u529F"
|
|
28
17
|
},
|
|
29
18
|
"BUSY": {
|
|
30
19
|
"errorcode": 1001,
|
|
31
|
-
"msg": "
|
|
20
|
+
"msg": "\u7CFB\u7EDF\u7E41\u5FD9\uFF0C\u8BF7\u7A0D\u5019\u518D\u8BD5"
|
|
32
21
|
},
|
|
33
22
|
"WRONG_PARAMETER": {
|
|
34
23
|
"errorcode": 400,
|
|
35
|
-
"msg": "
|
|
24
|
+
"msg": "\u53C2\u6570\u9519\u8BEF"
|
|
36
25
|
},
|
|
37
26
|
"NOT_FOUND": {
|
|
38
27
|
"errorcode": 404,
|
|
39
|
-
"msg": "
|
|
28
|
+
"msg": "\u6570\u636E\u4E0D\u5B58\u5728"
|
|
40
29
|
},
|
|
41
30
|
"PERMISSION_DENIED": {
|
|
42
31
|
"errorcode": 403,
|
|
43
|
-
"msg": "
|
|
32
|
+
"msg": "\u6CA1\u6709\u6743\u9650"
|
|
44
33
|
},
|
|
45
34
|
"SERVER_BUSY": {
|
|
46
35
|
"errorcode": 503,
|
|
47
|
-
"msg": "
|
|
36
|
+
"msg": "\u7CFB\u7EDF\u7E41\u5FD9\uFF0C\u8BF7\u7A0D\u5019\u518D\u8BD5"
|
|
48
37
|
},
|
|
49
38
|
"SERVER_TIMEOUT": {
|
|
50
39
|
"errorcode": 504,
|
|
51
|
-
"msg": "
|
|
40
|
+
"msg": "\u7CFB\u7EDF\u7E41\u5FD9\uFF0C\u8BF7\u7A0D\u5019\u518D\u8BD5"
|
|
52
41
|
},
|
|
53
42
|
"UNCHECK_ERROR": {
|
|
54
43
|
"errorcode": 9999999,
|
|
55
|
-
"msg": "
|
|
44
|
+
"msg": "\u7CFB\u7EDF\u8FDB\u5165\u4E86\u5F02\u6B21\u5143..."
|
|
56
45
|
}
|
|
57
46
|
};
|
|
58
47
|
/**
|
|
@@ -70,15 +59,15 @@ buildCodeMap();
|
|
|
70
59
|
* @param msg 返回信息<可选>
|
|
71
60
|
* @return 状态对象
|
|
72
61
|
*/ function getReturnCode(code, msg) {
|
|
73
|
-
if ((0, _utils.isBoolean
|
|
62
|
+
if ((0, _utils).isBoolean(code)) {
|
|
74
63
|
code = code ? 0 : -1;
|
|
75
64
|
}
|
|
76
65
|
var re;
|
|
77
66
|
switch(true){
|
|
78
|
-
case (0, _utils.isString
|
|
67
|
+
case (0, _utils).isString(code):
|
|
79
68
|
re = CODE_DETAIL[code];
|
|
80
69
|
break;
|
|
81
|
-
case (0, _utils.isNumber
|
|
70
|
+
case (0, _utils).isNumber(code):
|
|
82
71
|
re = CODE_DETAIL[CODE_MAP[code]] || CODE_DETAIL.UNCHECK_ERROR;
|
|
83
72
|
break;
|
|
84
73
|
default:
|
|
@@ -115,3 +104,7 @@ buildCodeMap();
|
|
|
115
104
|
return code;
|
|
116
105
|
}
|
|
117
106
|
});
|
|
107
|
+
exports.getReturnCode = getReturnCode;
|
|
108
|
+
exports.getCodeDetail = getCodeDetail;
|
|
109
|
+
exports.set = set;
|
|
110
|
+
exports.ErrorTypes = ErrorTypes;
|
|
@@ -2,34 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
X_MAC: ()=>X_MAC,
|
|
13
|
-
uuid: ()=>uuid
|
|
14
|
-
});
|
|
15
|
-
const _utils = require("@x-drive/utils");
|
|
16
|
-
const _os = require("os");
|
|
17
|
-
const _common = require("../common");
|
|
5
|
+
exports.uuid = exports.X_MAC = void 0;
|
|
6
|
+
var _utils = require("@x-drive/utils");
|
|
7
|
+
var _os = require("os");
|
|
8
|
+
var _common = require("../common");
|
|
18
9
|
var ref;
|
|
19
|
-
var netInterfaces = (0, _os.networkInterfaces
|
|
20
|
-
const X_MAC = ((ref = Object.keys(netInterfaces).sort().map((key)=>netInterfaces[key]
|
|
10
|
+
var netInterfaces = (0, _os).networkInterfaces();
|
|
11
|
+
const X_MAC = ((ref = Object.keys(netInterfaces).sort().map((key)=>netInterfaces[key]
|
|
12
|
+
).flat(1).find((en)=>{
|
|
21
13
|
return en && en.family && en.family.toLowerCase() === "ipv4" && en.mac !== "00:00:00:00:00:00" ? true : false;
|
|
22
14
|
})) === null || ref === void 0 ? void 0 : ref.mac) || null;
|
|
15
|
+
exports.X_MAC = X_MAC;
|
|
23
16
|
netInterfaces = null;
|
|
24
17
|
/**
|
|
25
18
|
* 生成一个 uuid
|
|
26
19
|
* @param one 第一节数据
|
|
27
20
|
* @param tow 第二节数据
|
|
28
21
|
*/ function uuid(one, tow) {
|
|
29
|
-
var r = (0, _utils.random
|
|
22
|
+
var r = (0, _utils).random(2333333, 23333).toString(16);
|
|
30
23
|
r = r.length < 6 ? r += "0" : r;
|
|
31
24
|
return [
|
|
32
|
-
(0, _common.getMD5
|
|
25
|
+
(0, _common).getMD5([
|
|
33
26
|
one,
|
|
34
27
|
X_MAC,
|
|
35
28
|
tow
|
|
@@ -38,3 +31,4 @@ netInterfaces = null;
|
|
|
38
31
|
r
|
|
39
32
|
].join("-");
|
|
40
33
|
}
|
|
34
|
+
exports.uuid = uuid;
|
package/dist/config/getEnv.js
CHANGED
|
@@ -2,11 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
get: ()=>_default
|
|
8
|
-
});
|
|
9
|
-
const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
7
|
function _interopRequireDefault(obj) {
|
|
11
8
|
return obj && obj.__esModule ? obj : {
|
|
12
9
|
default: obj
|
|
@@ -18,7 +15,7 @@ function _interopRequireDefault(obj) {
|
|
|
18
15
|
function getEnv(argv) {
|
|
19
16
|
return argv.ENV !== undefined ? argv.ENV : process.env && process.env.NODE_ENV && process.env.NODE_ENV.toLowerCase() || "development";
|
|
20
17
|
}
|
|
21
|
-
|
|
18
|
+
var _default = (argv)=>{
|
|
22
19
|
switch(getEnv(argv)){
|
|
23
20
|
case "0":
|
|
24
21
|
env = "DEVELOPMENT";
|
|
@@ -59,3 +56,4 @@ const _default = (argv)=>{
|
|
|
59
56
|
envAddConfPath
|
|
60
57
|
};
|
|
61
58
|
};
|
|
59
|
+
exports.default = _default;
|
package/dist/config/index.js
CHANGED
|
@@ -2,25 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
default: ()=>_default,
|
|
14
|
-
get: ()=>get,
|
|
15
|
-
update: ()=>update
|
|
16
|
-
});
|
|
17
|
-
const _processCustomConfigFiles = /*#__PURE__*/ _interopRequireDefault(require("./process-custom-config-files"));
|
|
18
|
-
const _processDefConfigFile = /*#__PURE__*/ _interopRequireDefault(require("./process-def-config-file"));
|
|
19
|
-
const _utils = require("@x-drive/utils");
|
|
20
|
-
const _log = require("../components/log");
|
|
21
|
-
const _cluster = /*#__PURE__*/ _interopRequireDefault(require("cluster"));
|
|
22
|
-
const _getEnv = /*#__PURE__*/ _interopRequireDefault(require("./getEnv"));
|
|
23
|
-
const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
|
|
5
|
+
exports.update = exports.get = exports.default = exports.log = void 0;
|
|
6
|
+
var _processCustomConfigFiles = _interopRequireDefault(require("./process-custom-config-files"));
|
|
7
|
+
var _processDefConfigFile = _interopRequireDefault(require("./process-def-config-file"));
|
|
8
|
+
var _utils = require("@x-drive/utils");
|
|
9
|
+
var _log = require("../components/log");
|
|
10
|
+
var _cluster = _interopRequireDefault(require("cluster"));
|
|
11
|
+
var _getEnv = _interopRequireDefault(require("./getEnv"));
|
|
12
|
+
var _path = _interopRequireDefault(require("path"));
|
|
24
13
|
function _interopRequireDefault(obj) {
|
|
25
14
|
return obj && obj.__esModule ? obj : {
|
|
26
15
|
default: obj
|
|
@@ -82,10 +71,10 @@ const logger = _log.globalLog.getLogger("config");
|
|
|
82
71
|
logger.info.apply(logger, rest);
|
|
83
72
|
}
|
|
84
73
|
}
|
|
85
|
-
const { env , envAddConfPath , isProd } = (0, _getEnv.default
|
|
86
|
-
const conf = (0, _processDefConfigFile.default
|
|
74
|
+
const { env , envAddConfPath , isProd } = (0, _getEnv).default(argv);
|
|
75
|
+
const conf = (0, _processDefConfigFile).default(argv);
|
|
87
76
|
theLog(`A [ ${env} ] server starting.`);
|
|
88
|
-
(0, _processCustomConfigFiles.default
|
|
77
|
+
(0, _processCustomConfigFiles).default(conf, env, envAddConfPath);
|
|
89
78
|
/**
|
|
90
79
|
* 默认配置
|
|
91
80
|
*/ const CONFIG = {
|
|
@@ -102,7 +91,7 @@ theLog(`A [ ${env} ] server starting.`);
|
|
|
102
91
|
"isMaster": IS_MASTER
|
|
103
92
|
};
|
|
104
93
|
try {
|
|
105
|
-
(0, _utils.extend
|
|
94
|
+
(0, _utils).extend(CONFIG, conf);
|
|
106
95
|
if (argv.PORT) {
|
|
107
96
|
const port = Number(argv.PORT);
|
|
108
97
|
if (!isNaN(port)) {
|
|
@@ -125,13 +114,17 @@ Object.keys(CONFIG).forEach(function(key) {
|
|
|
125
114
|
theLog(`${key} : ${val}`);
|
|
126
115
|
});
|
|
127
116
|
console.log("");
|
|
128
|
-
|
|
117
|
+
var _default = CONFIG;
|
|
118
|
+
exports.default = _default;
|
|
129
119
|
function get() {
|
|
130
120
|
return CONFIG;
|
|
131
121
|
}
|
|
132
|
-
/**更新配置 */ function update(
|
|
133
|
-
if ((0, _utils.isObject
|
|
134
|
-
(0, _utils.extend
|
|
122
|
+
/**更新配置 */ function update(conf1) {
|
|
123
|
+
if ((0, _utils).isObject(conf1)) {
|
|
124
|
+
(0, _utils).extend(CONFIG, conf1);
|
|
135
125
|
}
|
|
136
126
|
return CONFIG;
|
|
137
127
|
}
|
|
128
|
+
exports.log = commonLog;
|
|
129
|
+
exports.get = get;
|
|
130
|
+
exports.update = update;
|
|
@@ -2,15 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const _utils = require("@x-drive/utils");
|
|
12
|
-
const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
|
|
13
|
-
const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _common = require("../components/common");
|
|
7
|
+
var _defaultXConfig = _interopRequireDefault(require("../default-x-config"));
|
|
8
|
+
var _utils = require("@x-drive/utils");
|
|
9
|
+
var _path = _interopRequireDefault(require("path"));
|
|
10
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
14
11
|
function _interopRequireDefault(obj) {
|
|
15
12
|
return obj && obj.__esModule ? obj : {
|
|
16
13
|
default: obj
|
|
@@ -20,42 +17,42 @@ function customConfigProcessor(conf, env, envAddConfPath) {
|
|
|
20
17
|
// 业务自定义服务端业务文件夹
|
|
21
18
|
const customDir = _path.default.resolve(process.cwd(), _defaultXConfig.default.businessDir);
|
|
22
19
|
// 是否存在业务自定义服务端业务文件夹
|
|
23
|
-
const hasCustom = (0, _common.checkFileStat
|
|
20
|
+
const hasCustom = (0, _common).checkFileStat(customDir);
|
|
24
21
|
if (hasCustom) {
|
|
25
22
|
/**业务生产环境配置文件地址 */ let customConfPath = _path.default.resolve(customDir, "@config", "config.js");
|
|
26
|
-
/**是否有业务自定义配置 */ let hasCustomConf = (0, _common.checkFileStat
|
|
23
|
+
/**是否有业务自定义配置 */ let hasCustomConf = (0, _common).checkFileStat(customConfPath);
|
|
27
24
|
if (hasCustomConf) {
|
|
28
|
-
(0, _utils.merge
|
|
25
|
+
(0, _utils).merge(conf, (0, _common).getRealDefaultMod(require(customConfPath)));
|
|
29
26
|
}
|
|
30
27
|
}
|
|
31
28
|
if (envAddConfPath) {
|
|
32
|
-
const devConf = (0, _common.getRealDefaultMod
|
|
29
|
+
const devConf = (0, _common).getRealDefaultMod(require(_path.default.join("..", envAddConfPath)));
|
|
33
30
|
let extConf = {};
|
|
34
31
|
let customDevConf = {};
|
|
35
32
|
if (hasCustom) {
|
|
36
|
-
/**对应环境配置文件地址 */ let
|
|
37
|
-
if ((0, _common.checkFileStat
|
|
38
|
-
customDevConf = (0, _common.getRealDefaultMod
|
|
33
|
+
/**对应环境配置文件地址 */ let customConfPath = _path.default.resolve(customDir, `${envAddConfPath}.js`);
|
|
34
|
+
if ((0, _common).checkFileStat(customConfPath)) {
|
|
35
|
+
customDevConf = (0, _common).getRealDefaultMod(require(customConfPath));
|
|
39
36
|
}
|
|
40
37
|
if (env === "DEVELOPMENT") {
|
|
41
38
|
let localConfPath = _path.default.resolve(customDir, "@config", "config.lo.js");
|
|
42
|
-
if ((0, _common.checkFileStat
|
|
43
|
-
extConf = (0, _common.getRealDefaultMod
|
|
39
|
+
if ((0, _common).checkFileStat(localConfPath)) {
|
|
40
|
+
extConf = (0, _common).getRealDefaultMod(require(localConfPath));
|
|
44
41
|
extConf.hasLo = true;
|
|
45
42
|
}
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
// 合并
|
|
49
|
-
(0, _utils.merge
|
|
46
|
+
(0, _utils).merge(conf, devConf, customDevConf, extConf);
|
|
50
47
|
}
|
|
51
48
|
// apis文件夹配置处理
|
|
52
49
|
if (hasCustom) {
|
|
53
50
|
const APIS_PATH = _path.default.resolve(process.cwd(), _defaultXConfig.default.businessDir, "@config", "@apis");
|
|
54
|
-
if ((0, _common.checkFileStat
|
|
51
|
+
if ((0, _common).checkFileStat(APIS_PATH) && conf.passExtApis !== true) {
|
|
55
52
|
let apis = [];
|
|
56
53
|
_fs.default.readdirSync(APIS_PATH).forEach((file)=>{
|
|
57
54
|
if (!file.startsWith(".") && _path.default.extname(file) === ".js") {
|
|
58
|
-
apis.push((0, _common.getRealDefaultMod
|
|
55
|
+
apis.push((0, _common).getRealDefaultMod(require(`${APIS_PATH}/${file}`)));
|
|
59
56
|
}
|
|
60
57
|
});
|
|
61
58
|
if (apis.length) {
|
|
@@ -65,4 +62,5 @@ function customConfigProcessor(conf, env, envAddConfPath) {
|
|
|
65
62
|
}
|
|
66
63
|
}
|
|
67
64
|
}
|
|
68
|
-
|
|
65
|
+
var _default = customConfigProcessor;
|
|
66
|
+
exports.default = _default;
|
|
@@ -2,13 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const _common = require("../components/common");
|
|
10
|
-
const _config = /*#__PURE__*/ _interopRequireDefault(require("../@config/config"));
|
|
11
|
-
const _path = require("path");
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _common = require("../components/common");
|
|
7
|
+
var _config = _interopRequireDefault(require("../@config/config"));
|
|
8
|
+
var _path = require("path");
|
|
12
9
|
function _interopRequireDefault(obj) {
|
|
13
10
|
return obj && obj.__esModule ? obj : {
|
|
14
11
|
default: obj
|
|
@@ -19,13 +16,14 @@ function defConfigProcessor(argv) {
|
|
|
19
16
|
// 绑定 IP
|
|
20
17
|
(_config.default).ip = argv.IP;
|
|
21
18
|
}
|
|
22
|
-
const apiPath = (0, _path.resolve
|
|
19
|
+
const apiPath = (0, _path).resolve("..", "@config", "@apis", "index.js");
|
|
23
20
|
// api 配置文件处理
|
|
24
|
-
var hasDefApiConf = (0, _common.checkFileStat
|
|
21
|
+
var hasDefApiConf = (0, _common).checkFileStat(apiPath, true);
|
|
25
22
|
if (hasDefApiConf) {
|
|
26
|
-
_config.default.apis = Object.assign(_config.default.apis || {}, (0, _common.getRealDefaultMod
|
|
23
|
+
_config.default.apis = Object.assign(_config.default.apis || {}, (0, _common).getRealDefaultMod(require(apiPath)));
|
|
27
24
|
}
|
|
28
25
|
hasDefApiConf = null;
|
|
29
26
|
return _config.default;
|
|
30
27
|
}
|
|
31
|
-
|
|
28
|
+
var _default = defConfigProcessor;
|
|
29
|
+
exports.default = _default;
|
package/dist/custom.js
CHANGED
|
@@ -2,49 +2,47 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const _config = require("./config");
|
|
13
|
-
const _util = require("util");
|
|
14
|
-
const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _utils = require("@x-drive/utils");
|
|
7
|
+
var _common = require("./components/common");
|
|
8
|
+
var _defaultXConfig = _interopRequireDefault(require("./default-x-config"));
|
|
9
|
+
var _config = require("./config");
|
|
10
|
+
var _util = require("util");
|
|
11
|
+
var _path = _interopRequireDefault(require("path"));
|
|
15
12
|
function _interopRequireDefault(obj) {
|
|
16
13
|
return obj && obj.__esModule ? obj : {
|
|
17
14
|
default: obj
|
|
18
15
|
};
|
|
19
16
|
}
|
|
20
17
|
/**处理自定义业务 */ async function processCustom() {
|
|
21
|
-
const config = (0, _config.get
|
|
18
|
+
const config = (0, _config).get();
|
|
22
19
|
const CustomPath = _path.default.resolve(process.cwd(), _defaultXConfig.default.businessDir, "custom");
|
|
23
|
-
const hasCustom = (0, _common.checkFileStat
|
|
20
|
+
const hasCustom = (0, _common).checkFileStat(CustomPath);
|
|
24
21
|
if (!hasCustom) {
|
|
25
22
|
return;
|
|
26
23
|
}
|
|
27
|
-
if (!(0, _utils.isArray
|
|
24
|
+
if (!(0, _utils).isArray(config.custom) || !config.custom.length) {
|
|
28
25
|
return;
|
|
29
26
|
}
|
|
30
27
|
if (hasCustom) {
|
|
31
28
|
try {
|
|
32
29
|
for (const item of config.custom){
|
|
33
|
-
const isStrItem = (0, _utils.isString
|
|
30
|
+
const isStrItem = (0, _utils).isString(item);
|
|
34
31
|
const name = isStrItem ? item : item[0];
|
|
35
32
|
const conf = isStrItem ? null : item[1];
|
|
36
|
-
const mod = (0, _common.getRealDefaultMod
|
|
37
|
-
if ((0, _utils.isFunction
|
|
33
|
+
const mod = (0, _common).getRealDefaultMod(require(_path.default.resolve(CustomPath, name)));
|
|
34
|
+
if ((0, _utils).isFunction(mod)) {
|
|
38
35
|
mod(conf);
|
|
39
|
-
} else if ((0, _utils.isAsyncFunction
|
|
36
|
+
} else if ((0, _utils).isAsyncFunction(mod)) {
|
|
40
37
|
await mod(conf);
|
|
41
38
|
}
|
|
42
39
|
masterLog("custom", `[${name}] loaded`);
|
|
43
40
|
}
|
|
44
41
|
} catch (e) {
|
|
45
|
-
masterLog("custom", "error", (0, _util.inspect
|
|
42
|
+
masterLog("custom", "error", (0, _util).inspect(e));
|
|
46
43
|
}
|
|
47
44
|
}
|
|
48
45
|
console.log("");
|
|
49
46
|
}
|
|
50
|
-
|
|
47
|
+
var _default = processCustom;
|
|
48
|
+
exports.default = _default;
|
package/dist/default-x-config.js
CHANGED
|
@@ -2,20 +2,18 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
get: ()=>_default
|
|
8
|
-
});
|
|
9
|
-
const _utils = require("@x-drive/utils");
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _utils = require("@x-drive/utils");
|
|
10
7
|
/**默认业务目录 */ var businessDir = "@server";
|
|
11
8
|
let Config = class Config {
|
|
12
9
|
get businessDir() {
|
|
13
10
|
return businessDir;
|
|
14
11
|
}
|
|
15
12
|
set businessDir(val) {
|
|
16
|
-
if ((0, _utils.isString
|
|
13
|
+
if ((0, _utils).isString(val)) {
|
|
17
14
|
businessDir = val;
|
|
18
15
|
}
|
|
19
16
|
}
|
|
20
17
|
};
|
|
21
|
-
|
|
18
|
+
var _default = new Config;
|
|
19
|
+
exports.default = _default;
|
package/dist/dot-file.js
CHANGED
|
@@ -2,14 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const _nodeUtil = require("node:util");
|
|
11
|
-
const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
|
|
12
|
-
const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
|
|
5
|
+
exports.processDotFile = void 0;
|
|
6
|
+
var _utils = require("@x-drive/utils");
|
|
7
|
+
var _nodeUtil = require("node:util");
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
13
10
|
function _interopRequireDefault(obj) {
|
|
14
11
|
return obj && obj.__esModule ? obj : {
|
|
15
12
|
default: obj
|
|
@@ -30,13 +27,14 @@ function _interopRequireDefault(obj) {
|
|
|
30
27
|
for(let i = 0; i < lines.length; i++){
|
|
31
28
|
const line = lines[i];
|
|
32
29
|
const linePart = line.split(LINE_SPLIT_REGEXP);
|
|
33
|
-
if ((0, _utils.isArray
|
|
30
|
+
if ((0, _utils).isArray(linePart) && linePart.length === 2) {
|
|
34
31
|
global.XLAB[linePart[0]] = JSON.parse(linePart[1]);
|
|
35
32
|
}
|
|
36
33
|
}
|
|
37
34
|
} catch (e) {
|
|
38
35
|
if (e.code !== "ENOENT") {
|
|
39
|
-
logger.error((0, _nodeUtil.inspect
|
|
36
|
+
logger.error((0, _nodeUtil).inspect(e));
|
|
40
37
|
}
|
|
41
38
|
}
|
|
42
39
|
}
|
|
40
|
+
exports.processDotFile = processDotFile;
|
package/dist/global.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const _defaultXConfig = /*#__PURE__*/ _interopRequireDefault(require("./default-x-config"));
|
|
6
|
-
const _config = require("./config");
|
|
7
|
-
const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
|
|
2
|
+
var _defaultXConfig = _interopRequireDefault(require("./default-x-config"));
|
|
3
|
+
var _config = require("./config");
|
|
4
|
+
var _path = _interopRequireDefault(require("path"));
|
|
8
5
|
function _interopRequireDefault(obj) {
|
|
9
6
|
return obj && obj.__esModule ? obj : {
|
|
10
7
|
default: obj
|
|
@@ -52,7 +49,7 @@ global.requireService = requireService;
|
|
|
52
49
|
* 获取系统配置
|
|
53
50
|
* @param key 配置项
|
|
54
51
|
*/ function getSysConfig(key) {
|
|
55
|
-
const conf = (0, _config.get
|
|
52
|
+
const conf = (0, _config).get();
|
|
56
53
|
if (key) {
|
|
57
54
|
return conf[key];
|
|
58
55
|
}
|
|
@@ -63,7 +60,7 @@ global.getSysConfig = getSysConfig;
|
|
|
63
60
|
* 更新系统配置
|
|
64
61
|
* @param conf 配置项
|
|
65
62
|
*/ function setSysConfig(conf) {
|
|
66
|
-
(0, _config.update
|
|
63
|
+
(0, _config).update(conf);
|
|
67
64
|
}
|
|
68
65
|
global.setSysConfig = setSysConfig;
|
|
69
66
|
global.XLAB = {};
|
package/dist/init-env.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var _common = require("./components/common");
|
|
3
|
+
var _log = require("./components/log");
|
|
4
|
+
var _defaultXConfig = _interopRequireDefault(require("./default-x-config"));
|
|
5
|
+
var _path = require("path");
|
|
6
|
+
function _interopRequireDefault(obj) {
|
|
7
|
+
return obj && obj.__esModule ? obj : {
|
|
8
|
+
default: obj
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function tryToSetEnv() {
|
|
12
|
+
const envPath = (0, _path).resolve(process.cwd(), _defaultXConfig.default.businessDir, "@env", "index.js");
|
|
13
|
+
var hasInitModule = (0, _common).checkFileStat(envPath, true);
|
|
14
|
+
if (hasInitModule) {
|
|
15
|
+
(0, _log).globalLog("InitEnv", "Try to init env");
|
|
16
|
+
require(envPath);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
tryToSetEnv();
|
|
@@ -2,17 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
filter: ()=>filter,
|
|
13
|
-
default: ()=>_default
|
|
14
|
-
});
|
|
15
|
-
const _utils = require("@x-drive/utils");
|
|
5
|
+
exports.default = _default;
|
|
6
|
+
exports.filter = void 0;
|
|
7
|
+
var _utils = require("@x-drive/utils");
|
|
16
8
|
var conf;
|
|
17
9
|
const VER_RE = /\d+\.\d+\.\d+/;
|
|
18
10
|
var routeMobile;
|
|
@@ -46,8 +38,8 @@ var nowDay = new Date().getDate();
|
|
|
46
38
|
shuffle(m4h);
|
|
47
39
|
var logLen = 0;
|
|
48
40
|
for(let j = 1; j <= 24; j++){
|
|
49
|
-
let sIndex = (0, _utils.random
|
|
50
|
-
let sLen = Math.min((0, _utils.random
|
|
41
|
+
let sIndex = (0, _utils).random(59, 0);
|
|
42
|
+
let sLen = Math.min((0, _utils).random(PRE_MAX_NUM, PRE_MIN_NUM), 60 - sIndex);
|
|
51
43
|
if (sLen + logLen > MAX_COLLECT) {
|
|
52
44
|
sLen = MAX_COLLECT - logLen;
|
|
53
45
|
}
|
|
@@ -92,3 +84,4 @@ function _default() {
|
|
|
92
84
|
conf = getSysConfig();
|
|
93
85
|
routeMobile = conf.routeMobile;
|
|
94
86
|
}
|
|
87
|
+
exports.filter = filter;
|
|
@@ -2,15 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const _common = require("../components/common");
|
|
10
|
-
const _assets = require("../components/assets");
|
|
11
|
-
const s5xx = (0, _assets.get)("5xx");
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _common = require("../components/common");
|
|
7
|
+
var _assets = require("../components/assets");
|
|
8
|
+
const s5xx = (0, _assets).get("5xx");
|
|
12
9
|
const code_map = {
|
|
13
|
-
"404": (0, _assets.get
|
|
10
|
+
"404": (0, _assets).get("404"),
|
|
14
11
|
"503": s5xx,
|
|
15
12
|
"504": s5xx
|
|
16
13
|
};
|
|
@@ -29,8 +26,9 @@ function handler(ctx) {
|
|
|
29
26
|
dat = page_tpl.replace("{dat}", re);
|
|
30
27
|
}
|
|
31
28
|
} else {
|
|
32
|
-
dat = (0, _common.responseResult
|
|
29
|
+
dat = (0, _common).responseResult(false, re);
|
|
33
30
|
}
|
|
34
31
|
ctx.body = dat;
|
|
35
32
|
}
|
|
36
|
-
|
|
33
|
+
var _default = handler;
|
|
34
|
+
exports.default = _default;
|
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
});
|
|
9
|
-
const _koaCompress = /*#__PURE__*/ _interopRequireDefault(require("koa-compress"));
|
|
10
|
-
const _zlib = /*#__PURE__*/ _interopRequireDefault(require("zlib"));
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var _koaCompress = _interopRequireDefault(require("koa-compress"));
|
|
7
|
+
var _zlib = _interopRequireDefault(require("zlib"));
|
|
11
8
|
function _interopRequireDefault(obj) {
|
|
12
9
|
return obj && obj.__esModule ? obj : {
|
|
13
10
|
default: obj
|
|
@@ -31,6 +28,7 @@ function handler(config) {
|
|
|
31
28
|
gzipOpts.flush = _zlib.default[config.gzip.flush];
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
|
-
return (0, _koaCompress.default
|
|
31
|
+
return (0, _koaCompress).default(gzipOpts);
|
|
35
32
|
}
|
|
36
|
-
|
|
33
|
+
var _default = handler;
|
|
34
|
+
exports.default = _default;
|