@x-9lab/xlab 1.0.8 → 1.0.11
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/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])) {
|
|
@@ -56,6 +56,10 @@ function _default(config) {
|
|
|
56
56
|
ctx.set("Access-Control-Allow-Origin", origin);
|
|
57
57
|
ctx.set("Access-Control-Allow-Methods", "POST, GET, OPTIONS");
|
|
58
58
|
ctx.set("Access-Control-Allow-Credentials", "true");
|
|
59
|
+
const acrHeaders = ctx.headers["access-control-request-headers"];
|
|
60
|
+
if (acrHeaders) {
|
|
61
|
+
ctx.set("Access-Control-Allow-Headers", acrHeaders);
|
|
62
|
+
}
|
|
59
63
|
ctx.set("X-Cors", isLocal ? "local" : config.type || "custom");
|
|
60
64
|
} else {
|
|
61
65
|
ctx.set("X-Cors", "disabled");
|
|
@@ -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.11",
|
|
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",
|