@maiyunnet/kebab 8.4.0 → 8.5.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/doc/kebab-rag.md CHANGED
@@ -1410,7 +1410,7 @@ index/variables/VER.md
1410
1410
 
1411
1411
  # Variable: VER
1412
1412
 
1413
- > `const` **VER**: `"8.4.0"` = `'8.4.0'`
1413
+ > `const` **VER**: `"8.5.0"` = `'8.5.0'`
1414
1414
 
1415
1415
  Defined in: [index.ts:10](https://github.com/maiyunnet/kebab/blob/master/index.ts#L10)
1416
1416
 
@@ -11882,7 +11882,7 @@ Defined in: [lib/net/response.ts:30](https://github.com/maiyunnet/kebab/blob/mas
11882
11882
 
11883
11883
  > **getRawStream**(): `Readable` \| `null`
11884
11884
 
11885
- Defined in: [lib/net/response.ts:55](https://github.com/maiyunnet/kebab/blob/master/lib/net/response.ts#L55)
11885
+ Defined in: [lib/net/response.ts:65](https://github.com/maiyunnet/kebab/blob/master/lib/net/response.ts#L65)
11886
11886
 
11887
11887
  获取原生响应读取流对象
11888
11888
 
@@ -11896,7 +11896,7 @@ Defined in: [lib/net/response.ts:55](https://github.com/maiyunnet/kebab/blob/mas
11896
11896
 
11897
11897
  > **getStream**(): `Readable` \| `null`
11898
11898
 
11899
- Defined in: [lib/net/response.ts:48](https://github.com/maiyunnet/kebab/blob/master/lib/net/response.ts#L48)
11899
+ Defined in: [lib/net/response.ts:53](https://github.com/maiyunnet/kebab/blob/master/lib/net/response.ts#L53)
11900
11900
 
11901
11901
  获取响应读取流对象
11902
11902
 
@@ -11910,7 +11910,7 @@ Defined in: [lib/net/response.ts:48](https://github.com/maiyunnet/kebab/blob/mas
11910
11910
 
11911
11911
  > **setContent**(`v`): `void`
11912
11912
 
11913
- Defined in: [lib/net/response.ts:41](https://github.com/maiyunnet/kebab/blob/master/lib/net/response.ts#L41)
11913
+ Defined in: [lib/net/response.ts:46](https://github.com/maiyunnet/kebab/blob/master/lib/net/response.ts#L46)
11914
11914
 
11915
11915
  用户自定义的 content 内容
11916
11916
 
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  * --- 本文件用来定义每个目录实体地址的常量 ---
6
6
  */
7
7
  /** --- 当前系统版本号 --- */
8
- export declare const VER = "8.4.0";
8
+ export declare const VER = "8.5.0";
9
9
  /** --- 框架根目录,以 / 结尾 --- */
10
10
  export declare const ROOT_PATH: string;
11
11
  /** --- 框架的 LIB,以 / 结尾 --- */
package/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * --- 本文件用来定义每个目录实体地址的常量 ---
7
7
  */
8
8
  /** --- 当前系统版本号 --- */
9
- export const VER = '8.4.0';
9
+ export const VER = '8.5.0';
10
10
  // --- 服务端用的路径 ---
11
11
  const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
12
12
  /** --- /xxx/xxx --- */
@@ -16,7 +16,12 @@ export class Response {
16
16
  if (this._content) {
17
17
  return this._content;
18
18
  }
19
- return this._req ? this._req.getBuffer() : null;
19
+ try {
20
+ return this._req ? await this._req.getBuffer() : null;
21
+ }
22
+ catch {
23
+ return null;
24
+ }
20
25
  }
21
26
  /**
22
27
  * --- 用户自定义的 content 内容 ---
@@ -29,12 +34,22 @@ export class Response {
29
34
  * --- 获取响应读取流对象 ---
30
35
  */
31
36
  getStream() {
32
- return this._req ? this._req.getStream() : null;
37
+ try {
38
+ return this._req ? this._req.getStream() : null;
39
+ }
40
+ catch {
41
+ return null;
42
+ }
33
43
  }
34
44
  /**
35
45
  * --- 获取原生响应读取流对象 ---
36
46
  */
37
47
  getRawStream() {
38
- return this._req ? this._req.getRawStream() : null;
48
+ try {
49
+ return this._req ? this._req.getRawStream() : null;
50
+ }
51
+ catch {
52
+ return null;
53
+ }
39
54
  }
40
55
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maiyunnet/kebab",
3
- "version": "8.4.0",
3
+ "version": "8.5.0",
4
4
  "description": "Simple, easy-to-use, and fully-featured Node.js framework that is ready-to-use out of the box.",
5
5
  "type": "module",
6
6
  "keywords": [
package/sys/child.js CHANGED
@@ -303,7 +303,7 @@ async function requestHandler(req, res, https) {
303
303
  'rootPath': vhost.real + now,
304
304
  'urlBase': '/' + now,
305
305
  'path': path.slice(1),
306
- 'timer': timer
306
+ 'timer': timer,
307
307
  })) {
308
308
  return;
309
309
  }
@@ -577,14 +577,34 @@ function getVhostReal(root) {
577
577
  * @param hostname 当前的 hostname,不带端口
578
578
  */
579
579
  async function getVhostByHostname(hostname) {
580
- let vGlobal;
580
+ /** --- 全局泛匹配(*)的对象 --- */
581
+ let vGlobal = null;
582
+ /** --- 全局泛匹配(*)的真实路径,例如 /www/wwwroot/ --- */
581
583
  let vGlobalReal = '';
582
- let vSub;
584
+ /** --- 通配符匹配(*.abc.com)的对象 --- */
585
+ let vSub = null;
586
+ /** --- 通配符匹配(*.abc.com)的真实路径,例如 /www/wwwroot/abc/ --- */
583
587
  let vSubReal = '';
584
- for (const vhost of vhosts) {
588
+ /** --- 条目循环标签 --- */
589
+ vhostLoop: for (const vhost of vhosts) {
585
590
  for (let domain of vhost.domains) {
591
+ if (domain === hostname) {
592
+ // --- 完全匹配 ---
593
+ const real = getVhostReal(vhost.root);
594
+ if (await lFs.isDir(real)) {
595
+ return { ...vhost, real };
596
+ }
597
+ }
598
+ if (vSub && vGlobal) {
599
+ // --- 意味着已经找到了更精准的子域名匹配和全局匹配,后续所有 vhost 和 domain 无需再通过正则或磁盘 IO 进行匹配判断 ---
600
+ break vhostLoop;
601
+ }
586
602
  if (domain === '*') {
587
603
  // --- 全局泛匹配 ---
604
+ if (vGlobal) {
605
+ // --- 已经有了全局匹配结果,无需重复赋值,跳过后续逻辑以节省性能 ---
606
+ continue;
607
+ }
588
608
  const real = getVhostReal(vhost.root);
589
609
  if (await lFs.isDir(real)) {
590
610
  vGlobal = vhost;
@@ -593,8 +613,12 @@ async function getVhostByHostname(hostname) {
593
613
  }
594
614
  else if (domain.includes('*')) {
595
615
  // --- 通配符匹配 ---
596
- domain = domain.replace(/\./g, '\\.').replace(/\*/g, '[\\w-]+?');
597
- if (new RegExp(`^${domain}$`).test(hostname)) {
616
+ if (vSub) {
617
+ // --- 已经存在子域名通配符匹配结果,按照优先级不再寻找其他通配符匹配,跳过正则计算 ---
618
+ continue;
619
+ }
620
+ const pattern = domain.replace(/\./g, '\\.').replace(/\*/g, '[\\w-]+?');
621
+ if (new RegExp(`^${pattern}$`).test(hostname)) {
598
622
  const real = getVhostReal(vhost.root);
599
623
  if (await lFs.isDir(real)) {
600
624
  vSub = vhost;
@@ -602,13 +626,6 @@ async function getVhostByHostname(hostname) {
602
626
  }
603
627
  }
604
628
  }
605
- else if (domain === hostname) {
606
- // --- 完全匹配 ---
607
- const real = getVhostReal(vhost.root);
608
- if (await lFs.isDir(real)) {
609
- return { ...vhost, real };
610
- }
611
- }
612
629
  }
613
630
  }
614
631
  if (vSub) {
@@ -106,8 +106,7 @@ export default class extends sCtr.Ctr {
106
106
  `<br><a href="${this._config.const.urlBase}test/json?type=9">View "test/json?type=9"</a>`,
107
107
  '<br><br><b>Ctr:</b>',
108
108
  `<br><br><a href="${this._config.const.urlBase}test/ctr-xsrf">View "test/ctr-xsrf"</a>`,
109
- `<br><a href="${this._config.const.urlBase}test/ctr-checkinput">View "test/ctr-checkinput"</a>`,
110
- `<br><a href="${this._config.const.urlBase}test/ctr-checkinput-schema">View "test/ctr-checkinput-schema"</a>`,
109
+ `<br><a href="${this._config.const.urlBase}test/ctr-checkinput">View "test/ctr-checkinput"</a> <a href="${this._config.const.urlBase}test/ctr-checkinput-schema">schema</a>`,
111
110
  `<br><a href="${this._config.const.urlBase}test/ctr-locale">View "test/ctr-locale"</a>`,
112
111
  `<br><a href="${this._config.const.urlBase}test/ctr-cachettl">View "test/ctr-cachettl"</a>`,
113
112
  `<br><a href="${this._config.const.urlBase}test/ctr-httpcode">View "test/ctr-httpcode"</a>`,