@x-9lab/xlab 1.6.1 → 2.0.1
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/cluster.d.ts +15 -3
- package/@types/components/common/index.d.ts +1 -2
- package/@types/components/cron/index.d.ts +4 -4
- package/@types/components/log/index.d.ts +37 -2
- package/@types/config/index.d.ts +9 -5
- package/@types/custom.d.ts +25 -3
- package/@types/dot-file.d.ts +6 -0
- package/@types/global.d.ts +44 -56
- package/@types/index.d.ts +18 -0
- package/@types/init-env.d.ts +3 -1
- package/@types/middleware/handle-pre-dir.d.ts +1 -5
- package/@types/middleware/request-filter.d.ts +0 -1
- package/@types/middleware/service-mark.d.ts +1 -6
- package/@types/router.d.ts +25 -0
- package/@types/server.d.ts +28 -6
- package/MIGRATION.md +182 -0
- package/README.md +105 -86
- package/dist/@config/config.dev.js +7 -3
- package/dist/@config/config.js +7 -4
- package/dist/@config/config.sand.js +7 -3
- package/dist/bin/watch.js +36 -16
- package/dist/cluster.js +121 -44
- package/dist/components/assets/index.js +9 -5
- package/dist/components/cluster/index.js +17 -4
- package/dist/components/common/index.js +65 -45
- package/dist/components/cron/index.js +50 -27
- package/dist/components/header/index.js +32 -17
- package/dist/components/header/time.js +6 -2
- package/dist/components/index.js +1 -1
- package/dist/components/log/index.js +91 -87
- package/dist/components/mime/index.js +6 -2
- package/dist/components/return-code/index.js +33 -18
- package/dist/components/uuid/index.js +22 -13
- package/dist/config/getEnv.js +9 -5
- package/dist/config/index.js +98 -66
- package/dist/config/process-custom-config-files.js +26 -22
- package/dist/config/process-def-config-file.js +15 -11
- package/dist/custom.js +77 -28
- package/dist/default-x-config.js +9 -5
- package/dist/dot-file.js +42 -17
- package/dist/global.js +37 -31
- package/dist/index.js +100 -0
- package/dist/init-env.js +17 -9
- package/dist/middleware/@bin/html-filter.js +19 -7
- package/dist/middleware/bad-request.js +12 -8
- package/dist/middleware/compress.js +11 -7
- package/dist/middleware/cors.js +20 -7
- package/dist/middleware/fresh-filter.js +13 -7
- package/dist/middleware/handle-pre-dir.js +22 -17
- package/dist/middleware/request-filter.js +39 -25
- package/dist/middleware/service-mark.js +22 -25
- package/dist/middlewares.js +22 -20
- package/dist/router.js +174 -141
- package/dist/server.js +202 -93
- package/package.json +25 -29
- package/@types/business/utils/cookie/1.1.0/clean/index.d.ts +0 -3
- package/@types/business/utils/cookie/1.1.0/clean/js/index.d.ts +0 -2
- package/@types/components/cache/index.d.ts +0 -2
- package/@types/components/cache/lru.d.ts +0 -21
- package/@types/components/html-processor/index.d.ts +0 -9
- package/@types/components/injection/index.d.ts +0 -25
- package/@types/components/js-processor/index.d.ts +0 -5
- package/@types/components/md5/index.d.ts +0 -2
- package/@types/components/platform/index.d.ts +0 -21
- package/@types/components/proxy/index.d.ts +0 -26
- package/@types/components/querystring/index.d.ts +0 -25
- package/@types/components/redirect/index.d.ts +0 -11
- package/@types/components/request/helper.d.ts +0 -3
- package/@types/components/request/index.d.ts +0 -51
- package/@types/components/request/resolve-uri.d.ts +0 -6
- package/@types/components/version/index.d.ts +0 -26
- package/@types/env.d.ts +0 -1
package/dist/default-x-config.js
CHANGED
|
@@ -2,18 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
exports
|
|
6
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _utils = require("@x-drive/utils");
|
|
7
12
|
/**默认业务目录 */ var businessDir = "@server";
|
|
8
13
|
let Config = class Config {
|
|
9
14
|
get businessDir() {
|
|
10
15
|
return businessDir;
|
|
11
16
|
}
|
|
12
17
|
set businessDir(val) {
|
|
13
|
-
if ((0, _utils
|
|
18
|
+
if ((0, _utils.isString)(val)) {
|
|
14
19
|
businessDir = val;
|
|
15
20
|
}
|
|
16
21
|
}
|
|
17
22
|
};
|
|
18
|
-
|
|
19
|
-
exports.default = _default;
|
|
23
|
+
const _default = new Config;
|
package/dist/dot-file.js
CHANGED
|
@@ -2,17 +2,37 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get getXlabEnv () {
|
|
13
|
+
return getXlabEnv;
|
|
14
|
+
},
|
|
15
|
+
get processDotFile () {
|
|
16
|
+
return processDotFile;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _utils = require("@x-drive/utils");
|
|
20
|
+
const _nodeutil = require("node:util");
|
|
21
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
22
|
+
const _fs = /*#__PURE__*/ _interop_require_default(require("fs"));
|
|
23
|
+
function _interop_require_default(obj) {
|
|
11
24
|
return obj && obj.__esModule ? obj : {
|
|
12
25
|
default: obj
|
|
13
26
|
};
|
|
14
27
|
}
|
|
15
28
|
/**行分割正则 */ const LINE_SPLIT_REGEXP = /[\s]?=[\s]?/;
|
|
29
|
+
/**`.xlab` 环境数据存储对象 */ const XLAB = {};
|
|
30
|
+
/**
|
|
31
|
+
* 获取 `.xlab` 系列文件定义的环境数据
|
|
32
|
+
* @return 环境数据对象
|
|
33
|
+
*/ function getXlabEnv() {
|
|
34
|
+
return XLAB;
|
|
35
|
+
}
|
|
16
36
|
/**处理根目录下可能存在的配置文件 */ function processDotFile(env, logger) {
|
|
17
37
|
env = env.toLowerCase();
|
|
18
38
|
if (env === "production") {
|
|
@@ -21,20 +41,25 @@ function _interopRequireDefault(obj) {
|
|
|
21
41
|
env = `.${env}`;
|
|
22
42
|
}
|
|
23
43
|
const dotFile = _path.default.resolve(process.cwd(), `.xlab${env}`);
|
|
44
|
+
var fileStr;
|
|
24
45
|
try {
|
|
25
|
-
|
|
26
|
-
const lines = fileStr.split("\n");
|
|
27
|
-
for(let i = 0; i < lines.length; i++){
|
|
28
|
-
const line = lines[i];
|
|
29
|
-
const linePart = line.split(LINE_SPLIT_REGEXP);
|
|
30
|
-
if ((0, _utils).isArray(linePart) && linePart.length === 2) {
|
|
31
|
-
global.XLAB[linePart[0]] = JSON.parse(linePart[1]);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
46
|
+
fileStr = _fs.default.readFileSync(dotFile, "utf8");
|
|
34
47
|
} catch (e) {
|
|
35
48
|
if (e.code !== "ENOENT") {
|
|
36
|
-
logger.error((0,
|
|
49
|
+
logger.error((0, _nodeutil.inspect)(e));
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const lines = fileStr.split("\n");
|
|
54
|
+
for(let i = 0; i < lines.length; i++){
|
|
55
|
+
const linePart = lines[i].split(LINE_SPLIT_REGEXP);
|
|
56
|
+
if ((0, _utils.isArray)(linePart) && linePart.length === 2) {
|
|
57
|
+
// 按行解析, 单行数据异常不影响其他行
|
|
58
|
+
try {
|
|
59
|
+
XLAB[linePart[0]] = JSON.parse(linePart[1]);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
logger.error(`.xlab${env} 第 ${i + 1} 行解析失败:`, (0, _nodeutil.inspect)(e));
|
|
62
|
+
}
|
|
37
63
|
}
|
|
38
64
|
}
|
|
39
65
|
}
|
|
40
|
-
exports.processDotFile = processDotFile;
|
package/dist/global.js
CHANGED
|
@@ -1,8 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
function
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get getSysConfig () {
|
|
13
|
+
return getSysConfig;
|
|
14
|
+
},
|
|
15
|
+
get requireMod () {
|
|
16
|
+
return requireMod;
|
|
17
|
+
},
|
|
18
|
+
get requireModel () {
|
|
19
|
+
return requireModel;
|
|
20
|
+
},
|
|
21
|
+
get requireService () {
|
|
22
|
+
return requireService;
|
|
23
|
+
},
|
|
24
|
+
get setSysConfig () {
|
|
25
|
+
return setSysConfig;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const _defaultxconfig = /*#__PURE__*/ _interop_require_default(require("./default-x-config"));
|
|
29
|
+
const _config = require("./config");
|
|
30
|
+
const _path = /*#__PURE__*/ _interop_require_default(require("path"));
|
|
31
|
+
function _interop_require_default(obj) {
|
|
6
32
|
return obj && obj.__esModule ? obj : {
|
|
7
33
|
default: obj
|
|
8
34
|
};
|
|
@@ -16,51 +42,31 @@ function _interopRequireDefault(obj) {
|
|
|
16
42
|
return _path.default.resolve(root || __dirname, "components", name);
|
|
17
43
|
}
|
|
18
44
|
/**
|
|
19
|
-
*
|
|
45
|
+
* 获取内置组件
|
|
20
46
|
* @param name 模块名
|
|
21
47
|
* @return 模块对象
|
|
22
48
|
*/ function requireMod(name) {
|
|
23
49
|
return require(getModulePath(name));
|
|
24
50
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* model 存放路径
|
|
28
|
-
*/ const MODEL_PATH = _path.default.resolve(process.cwd(), _defaultXConfig.default.businessDir, "business", "@models");
|
|
29
|
-
/**
|
|
30
|
-
* 全局获取 model 的方法
|
|
31
|
-
* @param name model 名称
|
|
32
|
-
* @return model 模块
|
|
33
|
-
*/ function requireModel(name) {
|
|
34
|
-
return require(_path.default.resolve(MODEL_PATH, name));
|
|
51
|
+
function requireModel(name) {
|
|
52
|
+
return require(_path.default.resolve(process.cwd(), _defaultxconfig.default.businessDir, "business", "@models", name));
|
|
35
53
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
* services 存放目录
|
|
39
|
-
*/ const SERVICES_PATH = _path.default.resolve(process.cwd(), _defaultXConfig.default.businessDir, "business", "@services");
|
|
40
|
-
/**
|
|
41
|
-
* 全局获取 service 的方法
|
|
42
|
-
* @param name service 名称
|
|
43
|
-
* @return service 模块
|
|
44
|
-
*/ function requireService(name) {
|
|
45
|
-
return require(_path.default.resolve(SERVICES_PATH, name));
|
|
54
|
+
function requireService(name) {
|
|
55
|
+
return require(_path.default.resolve(process.cwd(), _defaultxconfig.default.businessDir, "business", "@services", name));
|
|
46
56
|
}
|
|
47
|
-
global.requireService = requireService;
|
|
48
57
|
/**
|
|
49
58
|
* 获取系统配置
|
|
50
59
|
* @param key 配置项
|
|
51
60
|
*/ function getSysConfig(key) {
|
|
52
|
-
const conf = (0, _config
|
|
61
|
+
const conf = (0, _config.get)();
|
|
53
62
|
if (key) {
|
|
54
63
|
return conf[key];
|
|
55
64
|
}
|
|
56
65
|
return conf;
|
|
57
66
|
}
|
|
58
|
-
global.getSysConfig = getSysConfig;
|
|
59
67
|
/**
|
|
60
68
|
* 更新系统配置
|
|
61
69
|
* @param conf 配置项
|
|
62
70
|
*/ function setSysConfig(conf) {
|
|
63
|
-
(0, _config
|
|
71
|
+
(0, _config.update)(conf);
|
|
64
72
|
}
|
|
65
|
-
global.setSysConfig = setSysConfig;
|
|
66
|
-
global.XLAB = {}; // globalLogger.log("global")
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get Log () {
|
|
13
|
+
return _log.Log;
|
|
14
|
+
},
|
|
15
|
+
get app () {
|
|
16
|
+
return _server.app;
|
|
17
|
+
},
|
|
18
|
+
get boot () {
|
|
19
|
+
return _server.boot;
|
|
20
|
+
},
|
|
21
|
+
get default () {
|
|
22
|
+
return _default;
|
|
23
|
+
},
|
|
24
|
+
get defineApi () {
|
|
25
|
+
return _router.defineApi;
|
|
26
|
+
},
|
|
27
|
+
get exit () {
|
|
28
|
+
return _server.exit;
|
|
29
|
+
},
|
|
30
|
+
get getApp () {
|
|
31
|
+
return _server.getApp;
|
|
32
|
+
},
|
|
33
|
+
get getLogger () {
|
|
34
|
+
return _log.getLogger;
|
|
35
|
+
},
|
|
36
|
+
get getSysConfig () {
|
|
37
|
+
return _global.getSysConfig;
|
|
38
|
+
},
|
|
39
|
+
get getXlabEnv () {
|
|
40
|
+
return _dotfile.getXlabEnv;
|
|
41
|
+
},
|
|
42
|
+
get globalLog () {
|
|
43
|
+
return _log.globalLog;
|
|
44
|
+
},
|
|
45
|
+
get masterLog () {
|
|
46
|
+
return _config.log;
|
|
47
|
+
},
|
|
48
|
+
get requireMod () {
|
|
49
|
+
return _global.requireMod;
|
|
50
|
+
},
|
|
51
|
+
get requireModel () {
|
|
52
|
+
return _global.requireModel;
|
|
53
|
+
},
|
|
54
|
+
get requireService () {
|
|
55
|
+
return _global.requireService;
|
|
56
|
+
},
|
|
57
|
+
get setSysConfig () {
|
|
58
|
+
return _global.setSysConfig;
|
|
59
|
+
},
|
|
60
|
+
get shutdown () {
|
|
61
|
+
return _server.shutdown;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
const _server = /*#__PURE__*/ _interop_require_wildcard(require("./server"));
|
|
65
|
+
const _global = require("./global");
|
|
66
|
+
const _log = require("./components/log");
|
|
67
|
+
const _config = require("./config");
|
|
68
|
+
const _dotfile = require("./dot-file");
|
|
69
|
+
const _router = require("./router");
|
|
70
|
+
function _getRequireWildcardCache(nodeInterop) {
|
|
71
|
+
if (typeof WeakMap !== "function") return null;
|
|
72
|
+
var cacheBabelInterop = new WeakMap();
|
|
73
|
+
var cacheNodeInterop = new WeakMap();
|
|
74
|
+
return (_getRequireWildcardCache = function(nodeInterop) {
|
|
75
|
+
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
|
|
76
|
+
})(nodeInterop);
|
|
77
|
+
}
|
|
78
|
+
function _interop_require_wildcard(obj, nodeInterop) {
|
|
79
|
+
if (!nodeInterop && obj && obj.__esModule) return obj;
|
|
80
|
+
if (obj === null || typeof obj !== "object" && typeof obj !== "function") return {
|
|
81
|
+
default: obj
|
|
82
|
+
};
|
|
83
|
+
var cache = _getRequireWildcardCache(nodeInterop);
|
|
84
|
+
if (cache && cache.has(obj)) return cache.get(obj);
|
|
85
|
+
var newObj = {
|
|
86
|
+
__proto__: null
|
|
87
|
+
};
|
|
88
|
+
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
|
|
89
|
+
for(var key in obj){
|
|
90
|
+
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
91
|
+
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
|
|
92
|
+
if (desc && (desc.get || desc.set)) Object.defineProperty(newObj, key, desc);
|
|
93
|
+
else newObj[key] = obj[key];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
newObj.default = obj;
|
|
97
|
+
if (cache) cache.set(obj, newObj);
|
|
98
|
+
return newObj;
|
|
99
|
+
}
|
|
100
|
+
const _default = _server.default;
|
package/dist/init-env.js
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _common = require("./components/common");
|
|
12
|
+
const _defaultxconfig = /*#__PURE__*/ _interop_require_default(require("./default-x-config"));
|
|
13
|
+
const _path = require("path");
|
|
14
|
+
function _interop_require_default(obj) {
|
|
6
15
|
return obj && obj.__esModule ? obj : {
|
|
7
16
|
default: obj
|
|
8
17
|
};
|
|
9
18
|
}
|
|
10
|
-
function
|
|
11
|
-
const envPath = (0, _path
|
|
12
|
-
var hasInitModule = (0, _common
|
|
19
|
+
/**执行业务的 @env 环境预处理模块 */ function initEnv() {
|
|
20
|
+
const envPath = (0, _path.resolve)(process.cwd(), _defaultxconfig.default.businessDir, "@env", "index.js");
|
|
21
|
+
var hasInitModule = (0, _common.checkFileStat)(envPath, true);
|
|
13
22
|
if (hasInitModule) {
|
|
14
|
-
// globalLog("InitEnv", "Try to init env");
|
|
15
23
|
require(envPath);
|
|
16
24
|
}
|
|
17
25
|
}
|
|
18
|
-
|
|
26
|
+
const _default = initEnv;
|
|
@@ -2,9 +2,22 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: Object.getOwnPropertyDescriptor(all, name).get
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
get default () {
|
|
13
|
+
return _default;
|
|
14
|
+
},
|
|
15
|
+
get filter () {
|
|
16
|
+
return filter;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _utils = require("@x-drive/utils");
|
|
20
|
+
const _config = require("../../config");
|
|
8
21
|
var conf;
|
|
9
22
|
const VER_RE = /\d+\.\d+\.\d+/;
|
|
10
23
|
var routeMobile;
|
|
@@ -38,8 +51,8 @@ var nowDay = new Date().getDate();
|
|
|
38
51
|
shuffle(m4h);
|
|
39
52
|
var logLen = 0;
|
|
40
53
|
for(let j = 1; j <= 24; j++){
|
|
41
|
-
let sIndex = (0, _utils
|
|
42
|
-
let sLen = Math.min((0, _utils
|
|
54
|
+
let sIndex = (0, _utils.random)(59, 0);
|
|
55
|
+
let sLen = Math.min((0, _utils.random)(PRE_MAX_NUM, PRE_MIN_NUM), 60 - sIndex);
|
|
43
56
|
if (sLen + logLen > MAX_COLLECT) {
|
|
44
57
|
sLen = MAX_COLLECT - logLen;
|
|
45
58
|
}
|
|
@@ -81,7 +94,6 @@ function filter(url) {
|
|
|
81
94
|
return data;
|
|
82
95
|
}
|
|
83
96
|
function _default() {
|
|
84
|
-
conf =
|
|
97
|
+
conf = (0, _config.get)();
|
|
85
98
|
routeMobile = conf.routeMobile;
|
|
86
99
|
}
|
|
87
|
-
exports.filter = filter;
|
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
exports
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _common = require("../components/common");
|
|
12
|
+
const _assets = require("../components/assets");
|
|
13
|
+
const s5xx = (0, _assets.get)("5xx");
|
|
9
14
|
const code_map = {
|
|
10
|
-
"404": (0, _assets
|
|
15
|
+
"404": (0, _assets.get)("404"),
|
|
11
16
|
"503": s5xx,
|
|
12
17
|
"504": s5xx
|
|
13
18
|
};
|
|
@@ -26,9 +31,8 @@ function handler(ctx) {
|
|
|
26
31
|
dat = page_tpl.replace("{dat}", re);
|
|
27
32
|
}
|
|
28
33
|
} else {
|
|
29
|
-
dat = (0, _common
|
|
34
|
+
dat = (0, _common.responseResult)(false, re);
|
|
30
35
|
}
|
|
31
36
|
ctx.body = dat;
|
|
32
37
|
}
|
|
33
|
-
|
|
34
|
-
exports.default = _default;
|
|
38
|
+
const _default = handler;
|
|
@@ -2,10 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
exports
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _koacompress = /*#__PURE__*/ _interop_require_default(require("koa-compress"));
|
|
12
|
+
const _zlib = /*#__PURE__*/ _interop_require_default(require("zlib"));
|
|
13
|
+
function _interop_require_default(obj) {
|
|
9
14
|
return obj && obj.__esModule ? obj : {
|
|
10
15
|
default: obj
|
|
11
16
|
};
|
|
@@ -28,7 +33,6 @@ function handler(config) {
|
|
|
28
33
|
gzipOpts.flush = _zlib.default[config.gzip.flush];
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
|
-
return (0,
|
|
36
|
+
return (0, _koacompress.default)(gzipOpts);
|
|
32
37
|
}
|
|
33
|
-
|
|
34
|
-
exports.default = _default;
|
|
38
|
+
const _default = handler;
|
package/dist/middleware/cors.js
CHANGED
|
@@ -2,8 +2,14 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
exports
|
|
6
|
-
|
|
5
|
+
Object.defineProperty(exports, /**跨域请求处理中间件初始化函数 */ "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _utils = require("@x-drive/utils");
|
|
12
|
+
const _config = require("../config");
|
|
7
13
|
/**
|
|
8
14
|
一些本地的域名或 ip
|
|
9
15
|
|
|
@@ -15,22 +21,29 @@ var _utils = require("@x-drive/utils");
|
|
|
15
21
|
/**根域获取正则 */ const ROOT_NAME_REGEXP = /[\w-]*\.(?:com|lo|cc|cn|asia|biz|coop|edu|gov|int|info|jobs|mobi|name|net|org|pro|tel|trave)(\.[a-z]{2})?/im;
|
|
16
22
|
/**获取域名根域 */ function getRootName(host) {
|
|
17
23
|
const match = host.match(ROOT_NAME_REGEXP);
|
|
18
|
-
if (match && (0, _utils
|
|
24
|
+
if (match && (0, _utils.isString)(match[0])) {
|
|
19
25
|
return match[0];
|
|
20
26
|
}
|
|
21
27
|
return null;
|
|
22
28
|
}
|
|
23
|
-
|
|
29
|
+
/**系统绑定的域名对应的根域, 首次使用时解析 */ var serverHostRootName = false;
|
|
30
|
+
/**获取系统绑定域名对应的根域 */ function getServerHostRootName() {
|
|
31
|
+
if (serverHostRootName === false) {
|
|
32
|
+
serverHostRootName = getRootName((0, _config.get)().host || "");
|
|
33
|
+
}
|
|
34
|
+
return serverHostRootName;
|
|
35
|
+
}
|
|
24
36
|
/**判断是否允许跨域 */ function isOneOfUs(origin, url, config = {}) {
|
|
25
37
|
if (config && config.enable === false) {
|
|
26
38
|
return false;
|
|
27
39
|
}
|
|
28
|
-
if ((0, _utils
|
|
40
|
+
if ((0, _utils.isFunction)(config.check)) {
|
|
29
41
|
return config.check(origin, url);
|
|
30
|
-
} else if ((0, _utils
|
|
42
|
+
} else if ((0, _utils.isString)(config.type)) {
|
|
31
43
|
if (config.type === "all") {
|
|
32
44
|
return true;
|
|
33
45
|
} else if (config.type === "sameroot") {
|
|
46
|
+
const ServerHostRootName = getServerHostRootName();
|
|
34
47
|
if (ServerHostRootName && getRootName(origin) === ServerHostRootName) {
|
|
35
48
|
return true;
|
|
36
49
|
} else {
|
|
@@ -42,7 +55,7 @@ var _utils = require("@x-drive/utils");
|
|
|
42
55
|
}
|
|
43
56
|
function _default(config) {
|
|
44
57
|
/**跨域请求处理中间件 */ async function cors(ctx, next) {
|
|
45
|
-
const { origin
|
|
58
|
+
const { origin } = ctx.headers;
|
|
46
59
|
if (!origin) {
|
|
47
60
|
await next();
|
|
48
61
|
return;
|
|
@@ -2,10 +2,16 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
exports
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
9
|
+
}
|
|
10
|
+
});
|
|
11
|
+
const _header = require("../components/header");
|
|
12
|
+
const _config = require("../config");
|
|
8
13
|
async function handle(ctx, next) {
|
|
14
|
+
const conf = (0, _config.get)();
|
|
9
15
|
// 头部字段
|
|
10
16
|
var pageUrl = ctx.state.parsedUrl && ctx.state.parsedUrl.pathname || ctx.url;
|
|
11
17
|
var queryMap = ctx.query;
|
|
@@ -22,7 +28,7 @@ async function handle(ctx, next) {
|
|
|
22
28
|
// 没有最后修改时间,附加上当前时间并继续
|
|
23
29
|
// 或者有nocache参数的话,也直接响应 200 操作
|
|
24
30
|
if (!conf["304"] || !!queryMap.no_cache || !modifiedSince) {
|
|
25
|
-
(0, _header
|
|
31
|
+
(0, _header.lastModified)(nowDateString, ctx);
|
|
26
32
|
await next();
|
|
27
33
|
// 发现有修改时间,直接返回304头
|
|
28
34
|
} else {
|
|
@@ -35,7 +41,7 @@ async function handle(ctx, next) {
|
|
|
35
41
|
ctx.status = 304;
|
|
36
42
|
ctx.body = "";
|
|
37
43
|
} else {
|
|
38
|
-
(0, _header
|
|
44
|
+
(0, _header.lastModified)(nowDateString, ctx);
|
|
39
45
|
await next();
|
|
40
46
|
}
|
|
41
47
|
// 其他的js/css/image静态资源设置两周的缓存时间(可配置)
|
|
@@ -45,12 +51,12 @@ async function handle(ctx, next) {
|
|
|
45
51
|
ctx.status = 304;
|
|
46
52
|
ctx.body = "";
|
|
47
53
|
} else {
|
|
48
|
-
(0, _header
|
|
54
|
+
(0, _header.lastModified)(nowDateString, ctx);
|
|
49
55
|
await next();
|
|
50
56
|
}
|
|
51
57
|
//其他类型的请求,比如Server API等等
|
|
52
58
|
} else {
|
|
53
|
-
(0, _header
|
|
59
|
+
(0, _header.lastModified)(nowDateString, ctx);
|
|
54
60
|
await next();
|
|
55
61
|
}
|
|
56
62
|
}
|
|
@@ -2,22 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
-
exports
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/ const replace_reg = new RegExp(conf.pathReplaceRegExp);
|
|
10
|
-
/**
|
|
11
|
-
* 处理代理过来多余的地址层级
|
|
12
|
-
*/ async function handlPreDir(ctx, next) {
|
|
13
|
-
if (replace_reg.test(ctx.url)) {
|
|
14
|
-
ctx.set("X-Pre-Dir", "Hit");
|
|
15
|
-
ctx.url = ctx.url.replace(replace_reg, "");
|
|
16
|
-
if (ctx.url.charAt(0) !== "/") {
|
|
17
|
-
ctx.url = "/" + ctx.url;
|
|
18
|
-
}
|
|
5
|
+
Object.defineProperty(exports, "default", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
get: function() {
|
|
8
|
+
return _default;
|
|
19
9
|
}
|
|
20
|
-
|
|
10
|
+
});
|
|
11
|
+
const _config = require("../config");
|
|
12
|
+
function _default() {
|
|
13
|
+
/**
|
|
14
|
+
* 路径处理匹配正则
|
|
15
|
+
*/ const replace_reg = new RegExp((0, _config.get)().pathReplaceRegExp);
|
|
16
|
+
/**
|
|
17
|
+
* 处理代理过来多余的地址层级
|
|
18
|
+
*/ return async function handlPreDir(ctx, next) {
|
|
19
|
+
if (replace_reg.test(ctx.url)) {
|
|
20
|
+
ctx.set("X-Pre-Dir", "Hit");
|
|
21
|
+
ctx.url = ctx.url.replace(replace_reg, "");
|
|
22
|
+
if (ctx.url.charAt(0) !== "/") {
|
|
23
|
+
ctx.url = "/" + ctx.url;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
await next();
|
|
27
|
+
};
|
|
21
28
|
}
|
|
22
|
-
var _default = handlPreDir;
|
|
23
|
-
exports.default = _default;
|