@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
package/@types/env.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/@types/server.d.ts
CHANGED
|
@@ -2,12 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>_default
|
|
8
|
-
});
|
|
5
|
+
exports.default = void 0;
|
|
9
6
|
const CONFIG = {
|
|
10
7
|
"304": false,
|
|
11
8
|
"workers": 0
|
|
12
9
|
};
|
|
13
|
-
|
|
10
|
+
var _default = CONFIG;
|
|
11
|
+
exports.default = _default;
|
package/dist/@config/config.js
CHANGED
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>_default
|
|
8
|
-
});
|
|
5
|
+
exports.default = void 0;
|
|
9
6
|
const CONFIG = {
|
|
10
7
|
"host": "",
|
|
11
8
|
"304": true,
|
|
@@ -22,4 +19,5 @@ const CONFIG = {
|
|
|
22
19
|
"root": "public",
|
|
23
20
|
"timezone": "Asia/Shanghai"
|
|
24
21
|
};
|
|
25
|
-
|
|
22
|
+
var _default = CONFIG;
|
|
23
|
+
exports.default = _default;
|
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>_default
|
|
8
|
-
});
|
|
5
|
+
exports.default = void 0;
|
|
9
6
|
const CONFIG = {};
|
|
10
|
-
|
|
7
|
+
var _default = CONFIG;
|
|
8
|
+
exports.default = _default;
|
package/dist/bin/watch.js
CHANGED
|
@@ -5,7 +5,7 @@ const crossSpawn = require("cross-spawn");
|
|
|
5
5
|
const colors = require("colors/safe");
|
|
6
6
|
const path = require("path");
|
|
7
7
|
const fs = require("fs");
|
|
8
|
-
/**输出内容名称 */ const X_LAB_STR = colors.bold(colors.cyan("
|
|
8
|
+
/**输出内容名称 */ const X_LAB_STR = colors.bold(colors.cyan("\uD83D\uDEF8 XLab"));
|
|
9
9
|
/**
|
|
10
10
|
* 子进程对象
|
|
11
11
|
* @type child_process.ChildProcess
|
|
@@ -90,7 +90,7 @@ const fs = require("fs");
|
|
|
90
90
|
} else {
|
|
91
91
|
if (initing) {
|
|
92
92
|
initing = false;
|
|
93
|
-
log("Watch
|
|
93
|
+
log("Watch \u6A21\u5F0F\u542F\u52A8\n");
|
|
94
94
|
setTimeout(()=>{
|
|
95
95
|
inited = true;
|
|
96
96
|
}, wait);
|
|
@@ -133,14 +133,14 @@ const fs = require("fs");
|
|
|
133
133
|
watch(chokidar, config, wait);
|
|
134
134
|
start();
|
|
135
135
|
} else {
|
|
136
|
-
log("
|
|
136
|
+
log("\u4E1A\u52A1\u81EA\u5B9A\u4E49\u76EE\u5F55\u4E0D\u5B58\u5728, watch \u6A21\u5F0F\u542F\u52A8\u5931\u8D25");
|
|
137
137
|
}
|
|
138
138
|
stats = null;
|
|
139
139
|
} else {
|
|
140
|
-
log("
|
|
140
|
+
log("\u8BF7\u5C06 chokidar \u5B89\u88C5\u5230\u5F00\u53D1\u4F9D\u8D56\u4E2D\u4EE5\u542F\u7528 watch \u6A21\u5F0F");
|
|
141
141
|
}
|
|
142
142
|
} else {
|
|
143
|
-
log("
|
|
143
|
+
log("\u914D\u7F6E\u4E0D\u5B58\u5728\u6216 watch.enable \u4E3A false, watch \u6A21\u5F0F\u542F\u52A8\u5931\u8D25\n", config);
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
module.exports = setup;
|
package/dist/cluster.js
CHANGED
|
@@ -2,74 +2,53 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const _cluster1 = /*#__PURE__*/ _interopRequireDefault(require("cluster"));
|
|
12
|
-
const _server = /*#__PURE__*/ _interopRequireDefault(require("./server"));
|
|
13
|
-
const _os = /*#__PURE__*/ _interopRequireDefault(require("os"));
|
|
5
|
+
exports.default = void 0;
|
|
6
|
+
var clusterCom = _interopRequireWildcard(require("./components/cluster"));
|
|
7
|
+
var _config = require("./config");
|
|
8
|
+
var _cluster = _interopRequireDefault(require("cluster"));
|
|
9
|
+
var _server = _interopRequireDefault(require("./server"));
|
|
10
|
+
var _os = _interopRequireDefault(require("os"));
|
|
14
11
|
function _interopRequireDefault(obj) {
|
|
15
12
|
return obj && obj.__esModule ? obj : {
|
|
16
13
|
default: obj
|
|
17
14
|
};
|
|
18
15
|
}
|
|
19
|
-
function
|
|
20
|
-
if (
|
|
21
|
-
var cacheBabelInterop = new WeakMap();
|
|
22
|
-
var cacheNodeInterop = new WeakMap();
|
|
23
|
-
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
24
|
-
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
25
|
-
})(nodeInterop);
|
|
26
|
-
}
|
|
27
|
-
function _interopRequireWildcard(obj, nodeInterop) {
|
|
28
|
-
if (!nodeInterop && obj && obj.__esModule) {
|
|
16
|
+
function _interopRequireWildcard(obj) {
|
|
17
|
+
if (obj && obj.__esModule) {
|
|
29
18
|
return obj;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
for(var key in obj){
|
|
43
|
-
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
44
|
-
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
45
|
-
if (desc && (desc.get || desc.set)) {
|
|
46
|
-
Object.defineProperty(newObj, key, desc);
|
|
47
|
-
} else {
|
|
48
|
-
newObj[key] = obj[key];
|
|
19
|
+
} else {
|
|
20
|
+
var newObj = {};
|
|
21
|
+
if (obj != null) {
|
|
22
|
+
for(var key in obj){
|
|
23
|
+
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
24
|
+
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
|
|
25
|
+
if (desc.get || desc.set) {
|
|
26
|
+
Object.defineProperty(newObj, key, desc);
|
|
27
|
+
} else {
|
|
28
|
+
newObj[key] = obj[key];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
49
31
|
}
|
|
50
32
|
}
|
|
33
|
+
newObj.default = obj;
|
|
34
|
+
return newObj;
|
|
51
35
|
}
|
|
52
|
-
newObj.default = obj;
|
|
53
|
-
if (cache) {
|
|
54
|
-
cache.set(obj, newObj);
|
|
55
|
-
}
|
|
56
|
-
return newObj;
|
|
57
36
|
}
|
|
58
37
|
const logger = log.getLogger("cluster");
|
|
59
38
|
const CPUnum = _os.default.cpus().length;
|
|
60
|
-
const config = (0, _config.get
|
|
39
|
+
const config = (0, _config).get();
|
|
61
40
|
/**
|
|
62
41
|
* 消息处理函数
|
|
63
42
|
* @param msg 消息配置对象
|
|
64
43
|
*/ function masterMessageHandler(msg) {
|
|
65
44
|
if (msg && msg.cmd) {
|
|
66
|
-
let handler =
|
|
45
|
+
let handler = clusterCom.get(msg.cmd);
|
|
67
46
|
if (handler) {
|
|
68
47
|
let args = msg.args || [];
|
|
69
48
|
args.push(msg.returnData);
|
|
70
49
|
let re = handler.apply(handler, args);
|
|
71
50
|
if (msg.wid) {
|
|
72
|
-
let worker =
|
|
51
|
+
let worker = _cluster.default.workers[msg.wid];
|
|
73
52
|
if (worker) {
|
|
74
53
|
worker.send({
|
|
75
54
|
"cmd": msg.cmd,
|
|
@@ -96,17 +75,17 @@ const config = (0, _config.get)();
|
|
|
96
75
|
// 小于使用数则取一半
|
|
97
76
|
let num = CPUnum < config.workers ? Math.ceil(CPUnum / 2) : config.workers;
|
|
98
77
|
for(var i = 0; i < num; i++){
|
|
99
|
-
|
|
78
|
+
_cluster.default.fork();
|
|
100
79
|
}
|
|
101
80
|
// if(!config.isProd){
|
|
102
|
-
|
|
103
|
-
masterLog("cluster", "info", "
|
|
81
|
+
_cluster.default.on("listening", function(worker, address) {
|
|
82
|
+
masterLog("cluster", "info", " Worker ", worker.process.pid, " online, Address: ", address.address, ":", address.port);
|
|
104
83
|
});
|
|
105
|
-
|
|
84
|
+
_cluster.default.on("message", masterMessageHandler);
|
|
106
85
|
// }
|
|
107
|
-
|
|
86
|
+
_cluster.default.on("exit", function(worker) {
|
|
108
87
|
logger.warn("Worker " + worker.process.pid + " is dead!");
|
|
109
|
-
|
|
88
|
+
_cluster.default.fork();
|
|
110
89
|
});
|
|
111
90
|
} else {
|
|
112
91
|
server = _server.default.listen(serverListenConf);
|
|
@@ -117,4 +96,5 @@ const config = (0, _config.get)();
|
|
|
117
96
|
}
|
|
118
97
|
return server;
|
|
119
98
|
}
|
|
120
|
-
|
|
99
|
+
var _default = start;
|
|
100
|
+
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 _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
|
|
10
|
-
const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
|
|
5
|
+
exports.get = void 0;
|
|
6
|
+
var _path = _interopRequireDefault(require("path"));
|
|
7
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
11
8
|
function _interopRequireDefault(obj) {
|
|
12
9
|
return obj && obj.__esModule ? obj : {
|
|
13
10
|
default: obj
|
|
@@ -29,3 +26,4 @@ try {
|
|
|
29
26
|
*/ function get(name) {
|
|
30
27
|
return ASSETS[name] || null;
|
|
31
28
|
}
|
|
29
|
+
exports.get = get;
|
|
@@ -2,17 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
get: ()=>get,
|
|
13
|
-
add: ()=>add,
|
|
14
|
-
del: ()=>del
|
|
15
|
-
});
|
|
5
|
+
exports.del = exports.add = exports.get = void 0;
|
|
16
6
|
/**
|
|
17
7
|
* 消息注册存储对象
|
|
18
8
|
*/ const MSG_HANDLERS = {};
|
|
@@ -38,3 +28,6 @@ _export(exports, {
|
|
|
38
28
|
*/ function del(cmd) {
|
|
39
29
|
delete MSG_HANDLERS[cmd];
|
|
40
30
|
}
|
|
31
|
+
exports.get = get;
|
|
32
|
+
exports.add = add;
|
|
33
|
+
exports.del = del;
|
|
@@ -2,36 +2,37 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
5
|
+
Object.defineProperty(exports, "sleep", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _utils.sleep;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "labelReplace", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function() {
|
|
14
|
+
return _utils.labelReplace;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "fix0", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function() {
|
|
20
|
+
return _utils.fix0;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(exports, "numberFormat", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
get: function() {
|
|
26
|
+
return _utils.numberFormat;
|
|
27
|
+
}
|
|
28
28
|
});
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
29
|
+
exports.getRealDefaultMod = exports.checkFileStat = exports.walk = exports.toJsonp = exports.formatJson = exports.object2Array = exports.md5 = exports.getMD5 = exports.responseResult = exports.params = exports.base64Toascii = exports.asciiTobase64 = void 0;
|
|
30
|
+
var _utils = require("@x-drive/utils");
|
|
31
|
+
var _returnCode = require("../return-code");
|
|
32
|
+
var _querystring = _interopRequireDefault(require("querystring"));
|
|
33
|
+
var _crypto = _interopRequireDefault(require("crypto"));
|
|
34
|
+
var _path = _interopRequireDefault(require("path"));
|
|
35
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
35
36
|
function _interopRequireDefault(obj) {
|
|
36
37
|
return obj && obj.__esModule ? obj : {
|
|
37
38
|
default: obj
|
|
@@ -83,7 +84,7 @@ function checkLogger() {
|
|
|
83
84
|
* @param msg 返回的提示性信息
|
|
84
85
|
* @return 数据对象
|
|
85
86
|
*/ function responseResult(status, result, msg) {
|
|
86
|
-
var code = (0, _utils.isObject
|
|
87
|
+
var code = (0, _utils).isObject(status) ? status : (0, _returnCode).getReturnCode(status);
|
|
87
88
|
var dat = {
|
|
88
89
|
"success": code.errorcode === 0,
|
|
89
90
|
"code": code.errorcode,
|
|
@@ -102,9 +103,9 @@ function checkLogger() {
|
|
|
102
103
|
return _crypto.default.createHash("md5").update(JSON.stringify(conditions), "utf8").digest("hex");
|
|
103
104
|
}
|
|
104
105
|
/**将一个输入字符串转为 md5 */ function md5(str) {
|
|
105
|
-
var
|
|
106
|
-
|
|
107
|
-
return
|
|
106
|
+
var md51 = _crypto.default.createHash("md5");
|
|
107
|
+
md51.update(str);
|
|
108
|
+
return md51.digest("hex");
|
|
108
109
|
}
|
|
109
110
|
/**
|
|
110
111
|
* 对象值转化为数组
|
|
@@ -185,3 +186,15 @@ function checkLogger() {
|
|
|
185
186
|
}
|
|
186
187
|
return mod;
|
|
187
188
|
}
|
|
189
|
+
exports.asciiTobase64 = asciiTobase64;
|
|
190
|
+
exports.base64Toascii = base64Toascii;
|
|
191
|
+
exports.params = params;
|
|
192
|
+
exports.responseResult = responseResult;
|
|
193
|
+
exports.getMD5 = getMD5;
|
|
194
|
+
exports.md5 = md5;
|
|
195
|
+
exports.object2Array = object2Array;
|
|
196
|
+
exports.formatJson = formatJson;
|
|
197
|
+
exports.toJsonp = toJsonp;
|
|
198
|
+
exports.walk = walk;
|
|
199
|
+
exports.checkFileStat = checkFileStat;
|
|
200
|
+
exports.getRealDefaultMod = getRealDefaultMod;
|
|
@@ -2,20 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
on: ()=>on,
|
|
13
|
-
kill: ()=>kill
|
|
14
|
-
});
|
|
15
|
-
const _utils = require("@x-drive/utils");
|
|
16
|
-
const _util = require("util");
|
|
17
|
-
const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
|
|
18
|
-
const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
|
|
5
|
+
exports.kill = exports.on = void 0;
|
|
6
|
+
var _utils = require("@x-drive/utils");
|
|
7
|
+
var _util = require("util");
|
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
|
9
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
19
10
|
function _interopRequireDefault(obj) {
|
|
20
11
|
return obj && obj.__esModule ? obj : {
|
|
21
12
|
default: obj
|
|
@@ -42,25 +33,25 @@ const config = getSysConfig("cron") || {
|
|
|
42
33
|
if (JOB_STATUS[name] === true) {
|
|
43
34
|
return;
|
|
44
35
|
}
|
|
45
|
-
var time = (0, _utils.isExecutable
|
|
36
|
+
var time = (0, _utils).isExecutable(mod.getDelay) ? mod.getDelay() : DEF_TIME;
|
|
46
37
|
if (isNaN(time)) {
|
|
47
38
|
logger.warn("[ %s ] Time Invalid.", name);
|
|
48
39
|
time = DEF_TIME;
|
|
49
40
|
}
|
|
50
|
-
const enable = (0, _utils.isExecutable
|
|
41
|
+
const enable = (0, _utils).isExecutable(mod.enable) ? mod.enable() === true : true;
|
|
51
42
|
if (!enable) {
|
|
52
43
|
return null;
|
|
53
44
|
}
|
|
54
45
|
if (!dont) {
|
|
55
46
|
JOB_STATUS[name] = true;
|
|
56
47
|
try {
|
|
57
|
-
if ((0, _utils.isExecutable
|
|
48
|
+
if ((0, _utils).isExecutable(mod)) {
|
|
58
49
|
mod();
|
|
59
|
-
} else if (mod.default && (0, _utils.isExecutable
|
|
50
|
+
} else if (mod.default && (0, _utils).isExecutable(mod.default())) {
|
|
60
51
|
mod.default();
|
|
61
52
|
}
|
|
62
53
|
} catch (e) {
|
|
63
|
-
logger.error((0, _util.inspect
|
|
54
|
+
logger.error((0, _util).inspect(e));
|
|
64
55
|
}
|
|
65
56
|
JOB_STATUS[name] = false;
|
|
66
57
|
}
|
|
@@ -90,7 +81,7 @@ const config = getSysConfig("cron") || {
|
|
|
90
81
|
dirStat = _fs.default.accessSync(cronPath, _fs.default.constants.F_OK);
|
|
91
82
|
} catch (e) {
|
|
92
83
|
dirStat = true;
|
|
93
|
-
logger.warn((0, _util.inspect
|
|
84
|
+
logger.warn((0, _util).inspect(e));
|
|
94
85
|
}
|
|
95
86
|
// accessSync 在文件不存在的时候才会返回内容
|
|
96
87
|
if (dirStat) {
|
|
@@ -112,7 +103,7 @@ const config = getSysConfig("cron") || {
|
|
|
112
103
|
}
|
|
113
104
|
}
|
|
114
105
|
} catch (err) {
|
|
115
|
-
logger.error((0, _util.inspect
|
|
106
|
+
logger.error((0, _util).inspect(err));
|
|
116
107
|
}
|
|
117
108
|
console.log("");
|
|
118
109
|
}
|
|
@@ -130,3 +121,5 @@ const config = getSysConfig("cron") || {
|
|
|
130
121
|
});
|
|
131
122
|
}
|
|
132
123
|
}
|
|
124
|
+
exports.on = on;
|
|
125
|
+
exports.kill = kill;
|
|
@@ -2,34 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
cacheControl: ()=>cacheControl,
|
|
13
|
-
expire: ()=>expire,
|
|
14
|
-
contentType: ()=>contentType,
|
|
15
|
-
lastModified: ()=>lastModified
|
|
16
|
-
});
|
|
17
|
-
const _utils = require("@x-drive/utils");
|
|
18
|
-
const _time = require("./time");
|
|
19
|
-
const _mime = require("../mime");
|
|
5
|
+
exports.lastModified = exports.contentType = exports.expire = exports.cacheControl = void 0;
|
|
6
|
+
var _utils = require("@x-drive/utils");
|
|
7
|
+
var _time = require("./time");
|
|
8
|
+
var _mime = require("../mime");
|
|
20
9
|
/**
|
|
21
10
|
* 设置 Cache-Control
|
|
22
11
|
* @param options max-age 缓存时间
|
|
23
12
|
* @param res 请求上下文
|
|
24
13
|
*/ function cacheControl(options, res) {
|
|
25
14
|
var age;
|
|
26
|
-
if ((0, _utils.isString
|
|
15
|
+
if ((0, _utils).isString(options)) {
|
|
27
16
|
if (options.indexOf("max-age") === -1) {
|
|
28
17
|
age = options;
|
|
29
18
|
} else {
|
|
30
|
-
age = "max-age=" + (0, _time.string2seconds
|
|
19
|
+
age = "max-age=" + (0, _time).string2seconds(options);
|
|
31
20
|
}
|
|
32
|
-
} else if ((0, _utils.isNumber
|
|
21
|
+
} else if ((0, _utils).isNumber(options)) {
|
|
33
22
|
age = "max-age=" + options;
|
|
34
23
|
}
|
|
35
24
|
if (age) {
|
|
@@ -42,9 +31,9 @@ const _mime = require("../mime");
|
|
|
42
31
|
* @param res 请求上下文
|
|
43
32
|
*/ function expire(options, res) {
|
|
44
33
|
var exp;
|
|
45
|
-
if ((0, _utils.isString
|
|
46
|
-
exp = new Date(Date.now() + (0, _time.string2seconds
|
|
47
|
-
} else if ((0, _utils.isNumber
|
|
34
|
+
if ((0, _utils).isString(options)) {
|
|
35
|
+
exp = new Date(Date.now() + (0, _time).string2seconds(options) * 1000);
|
|
36
|
+
} else if ((0, _utils).isNumber(options)) {
|
|
48
37
|
exp = new Date(Date.now() + options * 1000);
|
|
49
38
|
}
|
|
50
39
|
if (exp) {
|
|
@@ -57,7 +46,7 @@ const _mime = require("../mime");
|
|
|
57
46
|
* @param res 请求上下文
|
|
58
47
|
*/ function contentType(options, res) {
|
|
59
48
|
var type;
|
|
60
|
-
if ((0, _utils.isString
|
|
49
|
+
if ((0, _utils).isString(options)) {
|
|
61
50
|
type = _mime.MIME[options];
|
|
62
51
|
}
|
|
63
52
|
if (type) {
|
|
@@ -69,6 +58,10 @@ const _mime = require("../mime");
|
|
|
69
58
|
* @param options 最后更新时间,传入非 String 类型时会使用当前时间
|
|
70
59
|
* @param res 请求上下文
|
|
71
60
|
*/ function lastModified(options, res) {
|
|
72
|
-
var time = (0, _utils.isString
|
|
73
|
-
res.set(
|
|
61
|
+
var time = (0, _utils).isString(options) ? options : new Date().toUTCString();
|
|
62
|
+
res.set("Last-Modified", time);
|
|
74
63
|
}
|
|
64
|
+
exports.cacheControl = cacheControl;
|
|
65
|
+
exports.expire = expire;
|
|
66
|
+
exports.contentType = contentType;
|
|
67
|
+
exports.lastModified = lastModified;
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>string2seconds
|
|
8
|
-
});
|
|
5
|
+
exports.string2seconds = void 0;
|
|
9
6
|
/**一年的秒数 */ const YEAR_SEC = 365 * 24 * 60 * 60;
|
|
10
7
|
/**一月的秒数 */ const MONTH_SEC = 30 * 24 * 60 * 60;
|
|
11
8
|
/**一天的秒数 */ const DAY_SEC = 24 * 60 * 60;
|
|
@@ -35,3 +32,4 @@ Object.defineProperty(exports, "string2seconds", {
|
|
|
35
32
|
}
|
|
36
33
|
return sec;
|
|
37
34
|
}
|
|
35
|
+
exports.string2seconds = string2seconds;
|
|
@@ -2,19 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
Log: ()=>Log,
|
|
13
|
-
globalLog: ()=>globalLog
|
|
14
|
-
});
|
|
15
|
-
const _log4Js = /*#__PURE__*/ _interopRequireDefault(require("log4js"));
|
|
16
|
-
const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
|
|
17
|
-
const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
|
|
5
|
+
exports.globalLog = exports.Log = void 0;
|
|
6
|
+
var _log4Js = _interopRequireDefault(require("log4js"));
|
|
7
|
+
var _path = _interopRequireDefault(require("path"));
|
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
18
9
|
function _interopRequireDefault(obj) {
|
|
19
10
|
return obj && obj.__esModule ? obj : {
|
|
20
11
|
default: obj
|
|
@@ -110,3 +101,5 @@ const globalLog = new Log({
|
|
|
110
101
|
});
|
|
111
102
|
// 日志
|
|
112
103
|
global.log = globalLog;
|
|
104
|
+
exports.Log = Log;
|
|
105
|
+
exports.globalLog = globalLog;
|
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>MIME
|
|
8
|
-
});
|
|
5
|
+
exports.MIME = void 0;
|
|
9
6
|
const MIME = {
|
|
10
7
|
"html": "text/html",
|
|
11
8
|
"css": "text/css",
|
|
@@ -16,3 +13,4 @@ const MIME = {
|
|
|
16
13
|
"xml": "application/xml",
|
|
17
14
|
"json": "application/json"
|
|
18
15
|
};
|
|
16
|
+
exports.MIME = MIME;
|