@x-9lab/xlab 1.0.7 → 1.0.10
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.
|
@@ -1,4 +1,42 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import type Koa from "koa";
|
|
3
|
+
import url from "url";
|
|
4
|
+
/**资源类型 */
|
|
5
|
+
interface ISrcType {
|
|
6
|
+
/**是否是 js 文件 */
|
|
7
|
+
js: boolean;
|
|
8
|
+
/**是否是 html 文件 */
|
|
9
|
+
html: boolean;
|
|
10
|
+
/**是否是图片文件 */
|
|
11
|
+
img: boolean;
|
|
12
|
+
/**是否是 css 文件 */
|
|
13
|
+
css: boolean;
|
|
14
|
+
/**是否是文件夹 */
|
|
15
|
+
dir: boolean;
|
|
16
|
+
/**是否是静态文件 */
|
|
17
|
+
static: boolean;
|
|
18
|
+
/**是否是模板文件 */
|
|
19
|
+
tpl: boolean;
|
|
20
|
+
/**是否是字体文件 */
|
|
21
|
+
font: boolean;
|
|
22
|
+
}
|
|
23
|
+
declare module "koa" {
|
|
24
|
+
/**系统默认 state */
|
|
25
|
+
interface DefaultState {
|
|
26
|
+
/**资源类型 */
|
|
27
|
+
srcType: ISrcType;
|
|
28
|
+
/**请求域名 */
|
|
29
|
+
originHost: string | string[];
|
|
30
|
+
/**请求版本 */
|
|
31
|
+
ver: Record<string, string>;
|
|
32
|
+
/**
|
|
33
|
+
经过解析后的请求 url
|
|
34
|
+
|
|
35
|
+
@see `https://nodejs.org/dist/latest-v16.x/docs/api/url.html`
|
|
36
|
+
*/
|
|
37
|
+
parsedUrl: url.Url;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
2
40
|
declare function filter(ctx: Koa.Context, next: Koa.Next): Promise<void>;
|
|
3
41
|
export default function (): typeof filter;
|
|
4
42
|
export {};
|
package/README.md
CHANGED
|
@@ -184,7 +184,7 @@ X-9lab 通用服务端
|
|
|
184
184
|
|clearLocalStorage|`boolean`||是否每次都强制清除 LocalStorage|
|
|
185
185
|
|pathReplaceRegExp|`string`||处理代理过来多余的地址层级路径替换判断正则|
|
|
186
186
|
|routeMobile|`string`||移动端入口文件地址(旧版逻辑)|
|
|
187
|
-
|launchRouter|`Record<string, string>`||不同端入口地址设置, 由 `@x-
|
|
187
|
+
|launchRouter|`Record<string, string>`||不同端入口地址设置, 由 `@x-drive/launch-detect` 提供支持|
|
|
188
188
|
|cron|`{def?: number;}`|{"def": 60}|定时任务设置|
|
|
189
189
|
|injection|`string[]`|[]|注入参数列表|
|
|
190
190
|
|indexPageCacheTime|`number`||首页缓存时间|
|
package/dist/dot-file.js
CHANGED
|
@@ -6,9 +6,9 @@ Object.defineProperty(exports, "processDotFile", {
|
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: ()=>processDotFile
|
|
8
8
|
});
|
|
9
|
+
const _utils = require("@x-drive/utils");
|
|
9
10
|
const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
|
|
10
11
|
const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
|
|
11
|
-
const _utils = require("@x-drive/utils");
|
|
12
12
|
function _interopRequireDefault(obj) {
|
|
13
13
|
return obj && obj.__esModule ? obj : {
|
|
14
14
|
default: obj
|
package/dist/middleware/cors.js
CHANGED
|
@@ -15,7 +15,7 @@ const _utils = require("@x-drive/utils");
|
|
|
15
15
|
"localhost": true,
|
|
16
16
|
"127.0.0.1": true
|
|
17
17
|
};
|
|
18
|
-
/**根域获取正则 */ const ROOT_NAME_REGEXP = /[\w-]*\.(?:com|cc|cn|asia|biz|coop|edu|gov|int|info|jobs|mobi|name|net|org|pro|tel|trave)(\.[a-z]{2})?/im;
|
|
18
|
+
/**根域获取正则 */ 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;
|
|
19
19
|
/**获取域名根域 */ function getRootName(host) {
|
|
20
20
|
const match = host.match(ROOT_NAME_REGEXP);
|
|
21
21
|
if (match && (0, _utils.isString)(match[0])) {
|
|
@@ -98,6 +98,7 @@ async function filter(ctx, next) {
|
|
|
98
98
|
var parsedUrl = _url.default.parse(ctx.url);
|
|
99
99
|
var pathname = parsedUrl.pathname;
|
|
100
100
|
ctx.state.parsedUrl = parsedUrl;
|
|
101
|
+
ctx.state.originHost = ctx.headers["x-forwarded-host"] || ctx.headers.host;
|
|
101
102
|
var srcType = {
|
|
102
103
|
"js": false,
|
|
103
104
|
"html": false,
|
|
@@ -114,14 +115,12 @@ async function filter(ctx, next) {
|
|
|
114
115
|
// 提取页面必要的信息
|
|
115
116
|
// 由于 dir 也可能直接返回 HTML 页面
|
|
116
117
|
// 所以这里也需要经过 HTML 的过滤器处理
|
|
117
|
-
ctx.state.originHost = ctx.headers["x-forwarded-host"] || ctx.headers.host;
|
|
118
118
|
ctx.state.ver = (0, _htmlFilter.filter)(ctx.url);
|
|
119
119
|
} else if (isStatic(pathname)) {
|
|
120
120
|
srcType.static = true;
|
|
121
121
|
if (isHtml(pathname)) {
|
|
122
122
|
srcType.html = true;
|
|
123
123
|
// 提取页面必要的信息
|
|
124
|
-
ctx.state.originHost = ctx.headers["x-forwarded-host"] || ctx.headers.host;
|
|
125
124
|
ctx.state.ver = (0, _htmlFilter.filter)(ctx.url);
|
|
126
125
|
} else if (isJS(pathname)) {
|
|
127
126
|
srcType.js = true;
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@x-9lab/xlab",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "9lab 服务端模块",
|
|
5
|
-
"versionDesc": "
|
|
5
|
+
"versionDesc": "originHost 现在所有请求都会带上",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "swc src -D ./src/bin --config-file .swcrc -d dist -w",
|
|
8
8
|
"compile": "swc src -D ./src/bin --config-file .swcrc -d dist",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"koa-router": "11.0.1",
|
|
34
34
|
"http-proxy": "1.18.1",
|
|
35
35
|
"koa-compress": "5.1.0",
|
|
36
|
-
"@x-drive/utils": "1.1.
|
|
36
|
+
"@x-drive/utils": "1.1.23"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"co": "4.6.0",
|