@maiyunnet/kebab 9.26.1 → 9.26.3
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/abox/example.d.ts +1 -0
- package/abox/example.js +17 -0
- package/doc/kebab-rag.md +26 -22
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/fs.js +1 -1
- package/package.json +1 -1
- package/sys/child.js +43 -14
- package/sys/ctr.js +4 -7
- package/sys/route.js +15 -17
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function createPathGuard(exampleRoot: string): (candidate: string) => Promise<boolean>;
|
package/abox/example.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as fs from 'fs/promises';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
export function createPathGuard(exampleRoot) {
|
|
4
|
+
const normalizedRoot = path.resolve(exampleRoot);
|
|
5
|
+
let root;
|
|
6
|
+
return async (candidate) => {
|
|
7
|
+
root ??= fs.realpath(normalizedRoot).catch(() => normalizedRoot);
|
|
8
|
+
try {
|
|
9
|
+
const relative = path.relative(await root, await fs.realpath(candidate));
|
|
10
|
+
return relative === '' || relative !== '..' &&
|
|
11
|
+
!relative.startsWith('..' + path.sep) && !path.isAbsolute(relative);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
package/doc/kebab-rag.md
CHANGED
|
@@ -10,6 +10,10 @@ quick-start.md
|
|
|
10
10
|
|
|
11
11
|
也可以使用 pm2 启动项目,执行 `pm2 start npx --name "kebab" -- kebab` 即可。
|
|
12
12
|
|
|
13
|
+
内置示例仅在全局 `conf/config.json` 的 `debug` 为布尔值 `true` 时开放。为 `false` 或未设置时,示例的 HTTP 请求返回 403,WebSocket 连接关闭;检查早于示例中间件、代理及静态资源处理。普通业务项目不受此限制。
|
|
14
|
+
|
|
15
|
+
初始化命令默认设置 `debug: true`。生产环境应改为 `false` 并重载配置;开发环境开启示例时,仍应通过本机或受控开发网络访问,Host 限制不能替代身份认证。
|
|
16
|
+
|
|
13
17
|
## 目录
|
|
14
18
|
|
|
15
19
|
项目初始化后,会生成一些基础文件和目录,介绍如下:
|
|
@@ -1759,7 +1763,7 @@ index/variables/VER.md
|
|
|
1759
1763
|
|
|
1760
1764
|
# Variable: VER
|
|
1761
1765
|
|
|
1762
|
-
> `const` **VER**: `"9.26.
|
|
1766
|
+
> `const` **VER**: `"9.26.3"` = `'9.26.3'`
|
|
1763
1767
|
|
|
1764
1768
|
Defined in: [index.ts:9](https://github.com/maiyunnet/kebab/blob/master/index.ts#L9)
|
|
1765
1769
|
|
|
@@ -138278,7 +138282,7 @@ sys/route/functions/getFormData.md
|
|
|
138278
138282
|
|
|
138279
138283
|
> **getFormData**(`req`, `events?`, `limits?`): `Promise`\<`false` \| \{ `files`: `Record`\<`string`, [`IPostFile`](../../../index/interfaces/IPostFile.md) \| [`IPostFile`](../../../index/interfaces/IPostFile.md)[]\>; `post`: `Record`\<`string`, [`Json`](../../../index/type-aliases/Json.md)\>; \}\>
|
|
138280
138284
|
|
|
138281
|
-
Defined in: [sys/route.ts:
|
|
138285
|
+
Defined in: [sys/route.ts:1101](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1101)
|
|
138282
138286
|
|
|
138283
138287
|
获取 formdata 的 post
|
|
138284
138288
|
|
|
@@ -138321,7 +138325,7 @@ sys/route/functions/getPost.md
|
|
|
138321
138325
|
|
|
138322
138326
|
> **getPost**(`req`): `Promise`\<`false` \| \{ `input`: `string`; `post`: `Record`\<`string`, `any`\>; `raw`: `Record`\<`string`, `any`\>; \}\>
|
|
138323
138327
|
|
|
138324
|
-
Defined in: [sys/route.ts:
|
|
138328
|
+
Defined in: [sys/route.ts:936](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L936)
|
|
138325
138329
|
|
|
138326
138330
|
获取 post 对象(通常已自动获取),如果是文件上传(formdata)的情况则不获取
|
|
138327
138331
|
|
|
@@ -138352,7 +138356,7 @@ sys/route/functions/run.md
|
|
|
138352
138356
|
|
|
138353
138357
|
> **run**(`data`): `Promise`\<`boolean`\>
|
|
138354
138358
|
|
|
138355
|
-
Defined in: [sys/route.ts:
|
|
138359
|
+
Defined in: [sys/route.ts:109](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L109)
|
|
138356
138360
|
|
|
138357
138361
|
若为动态路径则执行此函数,此函数不进行判断 kebab.json 是否存在
|
|
138358
138362
|
|
|
@@ -138439,7 +138443,7 @@ sys/route/functions/unlinkUploadFiles.md
|
|
|
138439
138443
|
|
|
138440
138444
|
> **unlinkUploadFiles**(`cctr`): `Promise`\<`void`\>
|
|
138441
138445
|
|
|
138442
|
-
Defined in: [sys/route.ts:
|
|
138446
|
+
Defined in: [sys/route.ts:894](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L894)
|
|
138443
138447
|
|
|
138444
138448
|
删除本次请求所有已上传的临时文件
|
|
138445
138449
|
|
|
@@ -138468,7 +138472,7 @@ sys/route/functions/waitCtr.md
|
|
|
138468
138472
|
|
|
138469
138473
|
> **waitCtr**(`cctr`): `Promise`\<`void`\>
|
|
138470
138474
|
|
|
138471
|
-
Defined in: [sys/route.ts:
|
|
138475
|
+
Defined in: [sys/route.ts:914](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L914)
|
|
138472
138476
|
|
|
138473
138477
|
等待异步任务结束,并删除临时文件,如果结束后还有事务没关闭,则会在本函数中打印控制台并且写入 log 文件
|
|
138474
138478
|
此时其实已经给客户端返回了,此处等待不消耗客户端的等待时间
|
|
@@ -138522,7 +138526,7 @@ sys/route/interfaces/IFormDataError.md
|
|
|
138522
138526
|
|
|
138523
138527
|
# Interface: IFormDataError
|
|
138524
138528
|
|
|
138525
|
-
Defined in: [sys/route.ts:
|
|
138529
|
+
Defined in: [sys/route.ts:1056](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1056)
|
|
138526
138530
|
|
|
138527
138531
|
解析上传数据时的失败原因,只提供错误码和限制值,不带临时路径或异常对象
|
|
138528
138532
|
|
|
@@ -138532,7 +138536,7 @@ Defined in: [sys/route.ts:1059](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138532
138536
|
|
|
138533
138537
|
> **code**: `"INVALID_BOUNDARY"` \| `"FILE_TOO_LARGE"` \| `"TOTAL_TOO_LARGE"` \| `"FIELD_TOO_LARGE"` \| `"HEADER_TOO_LARGE"` \| `"TOO_MANY_PARTS"` \| `"FILE_TYPE"` \| `"TIMEOUT"` \| `"TEMP_FILE_ERROR"` \| `"REQUEST_ERROR"` \| `"REQUEST_ABORTED"`
|
|
138534
138538
|
|
|
138535
|
-
Defined in: [sys/route.ts:
|
|
138539
|
+
Defined in: [sys/route.ts:1057](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1057)
|
|
138536
138540
|
|
|
138537
138541
|
***
|
|
138538
138542
|
|
|
@@ -138540,7 +138544,7 @@ Defined in: [sys/route.ts:1060](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138540
138544
|
|
|
138541
138545
|
> `optional` **limit?**: `number`
|
|
138542
138546
|
|
|
138543
|
-
Defined in: [sys/route.ts:
|
|
138547
|
+
Defined in: [sys/route.ts:1061](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1061)
|
|
138544
138548
|
|
|
138545
138549
|
超出的限制值:大小用字节,超时用毫秒,字段和文件数量用个
|
|
138546
138550
|
|
|
@@ -138555,7 +138559,7 @@ sys/route/interfaces/IFormDataEvents.md
|
|
|
138555
138559
|
|
|
138556
138560
|
# Interface: IFormDataEvents
|
|
138557
138561
|
|
|
138558
|
-
Defined in: [sys/route.ts:
|
|
138562
|
+
Defined in: [sys/route.ts:1065](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1065)
|
|
138559
138563
|
|
|
138560
138564
|
multipart 文件处理及失败通知
|
|
138561
138565
|
|
|
@@ -138565,7 +138569,7 @@ multipart 文件处理及失败通知
|
|
|
138565
138569
|
|
|
138566
138570
|
> `optional` **onerror?**: (`error`) => `void`
|
|
138567
138571
|
|
|
138568
|
-
Defined in: [sys/route.ts:
|
|
138572
|
+
Defined in: [sys/route.ts:1073](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1073)
|
|
138569
138573
|
|
|
138570
138574
|
首次失败时调用一次,getFormData 返回 false;若连接已断开,可能无法回复客户端
|
|
138571
138575
|
|
|
@@ -138585,7 +138589,7 @@ Defined in: [sys/route.ts:1076](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138585
138589
|
|
|
138586
138590
|
> `optional` **onfiledata?**: (`chunk`) => `void`
|
|
138587
138591
|
|
|
138588
|
-
Defined in: [sys/route.ts:
|
|
138592
|
+
Defined in: [sys/route.ts:1069](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1069)
|
|
138589
138593
|
|
|
138590
138594
|
文件上传时触发,仅 start 返回 true 时触发
|
|
138591
138595
|
|
|
@@ -138605,7 +138609,7 @@ Defined in: [sys/route.ts:1072](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138605
138609
|
|
|
138606
138610
|
> `optional` **onfileend?**: () => `void`
|
|
138607
138611
|
|
|
138608
|
-
Defined in: [sys/route.ts:
|
|
138612
|
+
Defined in: [sys/route.ts:1071](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1071)
|
|
138609
138613
|
|
|
138610
138614
|
文件上传结束时触发,仅 start 返回 true 时触发
|
|
138611
138615
|
|
|
@@ -138619,7 +138623,7 @@ Defined in: [sys/route.ts:1074](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138619
138623
|
|
|
138620
138624
|
> `optional` **onfilestart?**: (`name`) => `boolean` \| `undefined`
|
|
138621
138625
|
|
|
138622
|
-
Defined in: [sys/route.ts:
|
|
138626
|
+
Defined in: [sys/route.ts:1067](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1067)
|
|
138623
138627
|
|
|
138624
138628
|
文件开始上传时触发,返回 true 则跳过该文件的保存
|
|
138625
138629
|
|
|
@@ -138644,7 +138648,7 @@ sys/route/interfaces/IFormDataLimits.md
|
|
|
138644
138648
|
|
|
138645
138649
|
# Interface: IFormDataLimits
|
|
138646
138650
|
|
|
138647
|
-
Defined in: [sys/route.ts:
|
|
138651
|
+
Defined in: [sys/route.ts:1077](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1077)
|
|
138648
138652
|
|
|
138649
138653
|
multipart 上传限制
|
|
138650
138654
|
|
|
@@ -138654,7 +138658,7 @@ multipart 上传限制
|
|
|
138654
138658
|
|
|
138655
138659
|
> `optional` **allowedExts?**: `string`[]
|
|
138656
138660
|
|
|
138657
|
-
Defined in: [sys/route.ts:
|
|
138661
|
+
Defined in: [sys/route.ts:1081](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1081)
|
|
138658
138662
|
|
|
138659
138663
|
允许的文件扩展名(含点号),如 ['.jpg', '.png', '.pdf']
|
|
138660
138664
|
|
|
@@ -138664,7 +138668,7 @@ Defined in: [sys/route.ts:1084](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138664
138668
|
|
|
138665
138669
|
> `optional` **maxFieldSize?**: `number`
|
|
138666
138670
|
|
|
138667
|
-
Defined in: [sys/route.ts:
|
|
138671
|
+
Defined in: [sys/route.ts:1083](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1083)
|
|
138668
138672
|
|
|
138669
138673
|
单个字段(非文件)最大字节数,默认 1 MB
|
|
138670
138674
|
|
|
@@ -138674,7 +138678,7 @@ Defined in: [sys/route.ts:1086](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138674
138678
|
|
|
138675
138679
|
> `optional` **maxFileSize?**: `number`
|
|
138676
138680
|
|
|
138677
|
-
Defined in: [sys/route.ts:
|
|
138681
|
+
Defined in: [sys/route.ts:1079](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1079)
|
|
138678
138682
|
|
|
138679
138683
|
单个文件最大字节数
|
|
138680
138684
|
|
|
@@ -138684,7 +138688,7 @@ Defined in: [sys/route.ts:1082](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138684
138688
|
|
|
138685
138689
|
> `optional` **maxHeaderSize?**: `number`
|
|
138686
138690
|
|
|
138687
|
-
Defined in: [sys/route.ts:
|
|
138691
|
+
Defined in: [sys/route.ts:1087](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1087)
|
|
138688
138692
|
|
|
138689
138693
|
每个字段或文件的 multipart 头部最多多少字节,默认 16 KB
|
|
138690
138694
|
|
|
@@ -138694,7 +138698,7 @@ Defined in: [sys/route.ts:1090](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138694
138698
|
|
|
138695
138699
|
> `optional` **maxParts?**: `number`
|
|
138696
138700
|
|
|
138697
|
-
Defined in: [sys/route.ts:
|
|
138701
|
+
Defined in: [sys/route.ts:1089](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1089)
|
|
138698
138702
|
|
|
138699
138703
|
multipart 字段与文件总数量,默认 1000
|
|
138700
138704
|
|
|
@@ -138704,7 +138708,7 @@ multipart 字段与文件总数量,默认 1000
|
|
|
138704
138708
|
|
|
138705
138709
|
> `optional` **maxTotalSize?**: `number`
|
|
138706
138710
|
|
|
138707
|
-
Defined in: [sys/route.ts:
|
|
138711
|
+
Defined in: [sys/route.ts:1085](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1085)
|
|
138708
138712
|
|
|
138709
138713
|
整体请求最大字节数,不设置或设为 0 则不限制
|
|
138710
138714
|
|
|
@@ -138714,6 +138718,6 @@ Defined in: [sys/route.ts:1088](https://github.com/maiyunnet/kebab/blob/master/s
|
|
|
138714
138718
|
|
|
138715
138719
|
> `optional` **timeout?**: `number`
|
|
138716
138720
|
|
|
138717
|
-
Defined in: [sys/route.ts:
|
|
138721
|
+
Defined in: [sys/route.ts:1091](https://github.com/maiyunnet/kebab/blob/master/sys/route.ts#L1091)
|
|
138718
138722
|
|
|
138719
138723
|
整体请求超时时间(毫秒),默认 5 分钟,设为 0 禁用超时
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
6
6
|
*/
|
|
7
7
|
/** --- 当前系统版本号 --- */
|
|
8
|
-
export const VER = '9.26.
|
|
8
|
+
export const VER = '9.26.3';
|
|
9
9
|
// --- 服务端用的路径 ---
|
|
10
10
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
11
11
|
/** --- /xxx/xxx --- */
|
package/lib/fs.js
CHANGED
|
@@ -414,7 +414,7 @@ async function* readFileRanges(path, ranges, headers, footer) {
|
|
|
414
414
|
export async function readToResponse(path, req, res, stat) {
|
|
415
415
|
stat ??= await stats(path);
|
|
416
416
|
if (!stat) {
|
|
417
|
-
const content = '<h1>404 Not found</h1
|
|
417
|
+
const content = '<h1>404 Not found</h1>';
|
|
418
418
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
419
419
|
lCore.writeHead(res, 404);
|
|
420
420
|
res.end(req.method === 'HEAD' ? '' : content);
|
package/package.json
CHANGED
package/sys/child.js
CHANGED
|
@@ -16,6 +16,22 @@ import * as sCtr from '#kebab/sys/ctr.js';
|
|
|
16
16
|
import * as kebab from '#kebab/index.js';
|
|
17
17
|
// --- 初始化 ---
|
|
18
18
|
import * as sRoute from '#kebab/sys/route.js';
|
|
19
|
+
import { createPathGuard } from '#kebab/abox/example.js';
|
|
20
|
+
/**
|
|
21
|
+
* --- 判断现有路径是否属于内置示例,符号链接按实际目标检查 ---
|
|
22
|
+
* @param candidate 已存在的目录或符号链接路径
|
|
23
|
+
* @returns 属于示例或无法确认目标时返回 true,由入口拒绝访问
|
|
24
|
+
*/
|
|
25
|
+
const isExamplePath = createPathGuard(kebab.ROOT_PATH + 'www/example/');
|
|
26
|
+
/**
|
|
27
|
+
* --- 拒绝生产环境中的示例 HTTP 请求 ---
|
|
28
|
+
* @param res 响应对象
|
|
29
|
+
* @returns 无返回值
|
|
30
|
+
*/
|
|
31
|
+
function rejectExample(res) {
|
|
32
|
+
lCore.writeHead(res, 403);
|
|
33
|
+
res.end('403 Forbidden');
|
|
34
|
+
}
|
|
19
35
|
/** --- 10 秒往主线程发送一次心跳的 Timer --- */
|
|
20
36
|
const hbTimer = setInterval(function () {
|
|
21
37
|
if (!process.connected || !process.send) {
|
|
@@ -33,8 +49,6 @@ const hbTimer = setInterval(function () {
|
|
|
33
49
|
const certList = new Map();
|
|
34
50
|
/** --- servername → certList mapKey 索引缓存 --- */
|
|
35
51
|
let certHostIndex = {};
|
|
36
|
-
/** --- 默认证书 --- */
|
|
37
|
-
let defaultSc;
|
|
38
52
|
/** --- 最后一次加载证书到内存的时间 --- */
|
|
39
53
|
let certLastLoad = 0;
|
|
40
54
|
/** --- 当前的虚拟主机配置列表 - 读取于 conf/vhost/*.json --- */
|
|
@@ -119,10 +133,6 @@ async function run() {
|
|
|
119
133
|
certHostIndex[servername] = mapKey;
|
|
120
134
|
return;
|
|
121
135
|
}
|
|
122
|
-
if (defaultSc) {
|
|
123
|
-
cb(null, defaultSc);
|
|
124
|
-
return;
|
|
125
|
-
}
|
|
126
136
|
lCore.display(`[CHILD][SNICallback] CERT NOT FOUND for servername: ${servername}`);
|
|
127
137
|
const err = new Error('CERT NOT FOUND');
|
|
128
138
|
cb(err);
|
|
@@ -211,15 +221,14 @@ async function requestHandler(req, res, https) {
|
|
|
211
221
|
// --- 已经开始输出的,需要用户自行处理 ---
|
|
212
222
|
return;
|
|
213
223
|
}
|
|
214
|
-
const content = '<h1>504 Gateway Timeout</h1
|
|
224
|
+
const content = '<h1>504 Gateway Timeout</h1>';
|
|
215
225
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
216
226
|
lCore.writeHead(res, 504);
|
|
217
227
|
res.end(content);
|
|
218
228
|
}
|
|
219
229
|
};
|
|
220
230
|
timer.timer = setTimeout(timer.callback, timer.timeout);
|
|
221
|
-
|
|
222
|
-
res.setHeader('Server', 'Kebab/' + kebab.VER);
|
|
231
|
+
res.setHeader('Server', 'Kebab');
|
|
223
232
|
res.setHeader('expires', 'Mon, 26 Jul 1994 05:00:00 GMT');
|
|
224
233
|
res.setHeader('cache-control', 'no-store');
|
|
225
234
|
// --- 停止中:通知 HTTP/1.1 客户端不要复用此连接(HTTP/2 由 GOAWAY 帧处理) ---
|
|
@@ -245,6 +254,12 @@ async function requestHandler(req, res, https) {
|
|
|
245
254
|
res.end('403 Forbidden');
|
|
246
255
|
return;
|
|
247
256
|
}
|
|
257
|
+
// --- 配置来自 JSON,仅布尔值 true 开放内置示例 ---
|
|
258
|
+
const debug = lCore.globalConfig.debug;
|
|
259
|
+
if (debug !== true && await isExamplePath(vhost.real)) {
|
|
260
|
+
rejectExample(res);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
248
263
|
/** --- 请求的路径部分,前导带 / 末尾不一定,用户怎么请求就是什么 --- */
|
|
249
264
|
let path = uri.pathname ?? '/';
|
|
250
265
|
if (path !== '/') {
|
|
@@ -262,13 +277,18 @@ async function requestHandler(req, res, https) {
|
|
|
262
277
|
/** --- 'abc' / 'def.json' --- */
|
|
263
278
|
let stat = await lFs.stats(vhost.real + now + item);
|
|
264
279
|
if (!stat) {
|
|
265
|
-
const content = '<h1>404 Not found</h1
|
|
280
|
+
const content = '<h1>404 Not found</h1>';
|
|
266
281
|
res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
267
282
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
268
283
|
lCore.writeHead(res, 404);
|
|
269
284
|
res.end(content);
|
|
270
285
|
return;
|
|
271
286
|
}
|
|
287
|
+
if (debug !== true && (stat.isDirectory() || stat.isSymbolicLink()) &&
|
|
288
|
+
await isExamplePath(vhost.real + now + item)) {
|
|
289
|
+
rejectExample(res);
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
272
292
|
if (stat.isDirectory()) {
|
|
273
293
|
now += item + '/';
|
|
274
294
|
// --- 判断是不是动态层 ---
|
|
@@ -298,7 +318,7 @@ async function requestHandler(req, res, https) {
|
|
|
298
318
|
'cookie': {},
|
|
299
319
|
'headers': {},
|
|
300
320
|
}, '[CHILD][requestHandler][E0]' + lText.stringifyError(e), '-error');
|
|
301
|
-
const content = '<h1>500 Server Error</h1
|
|
321
|
+
const content = '<h1>500 Server Error</h1>';
|
|
302
322
|
if (!res.headersSent) {
|
|
303
323
|
res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
304
324
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
@@ -341,7 +361,7 @@ async function requestHandler(req, res, https) {
|
|
|
341
361
|
}
|
|
342
362
|
catch (e) {
|
|
343
363
|
lCore.log({}, '[CHILD][requestHandler][E1]' + lText.stringifyError(e), '-error');
|
|
344
|
-
const content = '<h1>500 Server Error</h1
|
|
364
|
+
const content = '<h1>500 Server Error</h1>';
|
|
345
365
|
if (!res.headersSent) {
|
|
346
366
|
res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
347
367
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
@@ -364,7 +384,7 @@ async function requestHandler(req, res, https) {
|
|
|
364
384
|
return;
|
|
365
385
|
}
|
|
366
386
|
}
|
|
367
|
-
const content = '<h1>403 Forbidden</h1
|
|
387
|
+
const content = '<h1>403 Forbidden</h1>';
|
|
368
388
|
res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
369
389
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
370
390
|
lCore.writeHead(res, 403);
|
|
@@ -387,6 +407,11 @@ async function upgradeHandler(req, socket, https, head) {
|
|
|
387
407
|
socket.end();
|
|
388
408
|
return;
|
|
389
409
|
}
|
|
410
|
+
const debug = lCore.globalConfig.debug;
|
|
411
|
+
if (debug !== true && await isExamplePath(vhost.real)) {
|
|
412
|
+
socket.end();
|
|
413
|
+
return;
|
|
414
|
+
}
|
|
390
415
|
/** --- 请求的路径部分,前导带 / 末尾不一定,用户怎么请求就是什么 --- */
|
|
391
416
|
let path = uri.pathname ?? '/';
|
|
392
417
|
if (path !== '/') {
|
|
@@ -407,6 +432,11 @@ async function upgradeHandler(req, socket, https, head) {
|
|
|
407
432
|
socket.end();
|
|
408
433
|
return;
|
|
409
434
|
}
|
|
435
|
+
if (debug !== true && (stat.isDirectory() || stat.isSymbolicLink()) &&
|
|
436
|
+
await isExamplePath(vhost.real + now + item)) {
|
|
437
|
+
socket.end();
|
|
438
|
+
return;
|
|
439
|
+
}
|
|
410
440
|
if (stat.isDirectory()) {
|
|
411
441
|
now += item + '/';
|
|
412
442
|
// --- 判断是不是动态层 ---
|
|
@@ -547,7 +577,6 @@ async function reloadCert() {
|
|
|
547
577
|
}
|
|
548
578
|
}
|
|
549
579
|
}
|
|
550
|
-
defaultSc = certList.size > 0 ? certList.values().next().value.sc : undefined;
|
|
551
580
|
certHostIndex = {};
|
|
552
581
|
}
|
|
553
582
|
/**
|
package/sys/ctr.js
CHANGED
|
@@ -345,7 +345,7 @@ export class Ctr {
|
|
|
345
345
|
lCore.debug(`[CTR][_loadReactPage] ${message}`);
|
|
346
346
|
lCore.log(this, `[CTR][_loadReactPage] ${detail}`, '-error');
|
|
347
347
|
this._httpCode = 500;
|
|
348
|
-
return '<h1>500 Server Error</h1
|
|
348
|
+
return '<h1>500 Server Error</h1>';
|
|
349
349
|
}
|
|
350
350
|
/**
|
|
351
351
|
* --- 设置校验错误返回值 ---
|
|
@@ -983,12 +983,9 @@ export class Ctr {
|
|
|
983
983
|
if (!rtn) {
|
|
984
984
|
return false;
|
|
985
985
|
}
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
for (const key in rtn.files) {
|
|
990
|
-
this._files[key] = rtn.files[key];
|
|
991
|
-
}
|
|
986
|
+
// --- 保留集合引用,特殊字段名也只写成自有属性 ---
|
|
987
|
+
Object.defineProperties(this._post, Object.getOwnPropertyDescriptors(rtn.post));
|
|
988
|
+
Object.defineProperties(this._files, Object.getOwnPropertyDescriptors(rtn.files));
|
|
992
989
|
return true;
|
|
993
990
|
}
|
|
994
991
|
}
|
package/sys/route.js
CHANGED
|
@@ -37,7 +37,7 @@ export function clearKebabConfigs() {
|
|
|
37
37
|
* @param res 响应对象
|
|
38
38
|
*/
|
|
39
39
|
function respond500(res) {
|
|
40
|
-
const content = '<h1>500 Server Error</h1
|
|
40
|
+
const content = '<h1>500 Server Error</h1>';
|
|
41
41
|
if (!res.headersSent) {
|
|
42
42
|
res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
43
43
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
@@ -65,9 +65,8 @@ function setInputValue(target, key, value) {
|
|
|
65
65
|
* --- 输出 404 错误响应 ---
|
|
66
66
|
* @param res 响应对象
|
|
67
67
|
* @param config 配置对象(用于检查 #404 路由)
|
|
68
|
-
* @param path 请求路径
|
|
69
68
|
*/
|
|
70
|
-
function respond404(res, config
|
|
69
|
+
function respond404(res, config) {
|
|
71
70
|
if (config?.route?.['#404']) {
|
|
72
71
|
if (!res.headersSent) {
|
|
73
72
|
res.setHeader('location', lText.urlResolve(config.const.urlBase, config.route['#404']));
|
|
@@ -78,7 +77,7 @@ function respond404(res, config, path) {
|
|
|
78
77
|
}
|
|
79
78
|
return;
|
|
80
79
|
}
|
|
81
|
-
const content = '
|
|
80
|
+
const content = '<h1>404 Not found</h1>';
|
|
82
81
|
if (!res.headersSent) {
|
|
83
82
|
res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
84
83
|
res.setHeader('content-length', Buffer.byteLength(content));
|
|
@@ -98,7 +97,7 @@ export async function run(data) {
|
|
|
98
97
|
const configContent = await lFs.getContent(data.rootPath + 'kebab.json', 'utf8');
|
|
99
98
|
if (!configContent) {
|
|
100
99
|
if (data.res) {
|
|
101
|
-
const content = '<h1>500
|
|
100
|
+
const content = '<h1>500 Server Error</h1>';
|
|
102
101
|
data.res.setHeader('content-type', 'text/html; charset=utf-8');
|
|
103
102
|
data.res.setHeader('content-length', Buffer.byteLength(content));
|
|
104
103
|
lCore.writeHead(data.res, 500);
|
|
@@ -260,7 +259,7 @@ export async function run(data) {
|
|
|
260
259
|
// --- 若文件名为保留的 middle 将不允许进行 ---
|
|
261
260
|
if (pathLeft.startsWith('middle')) {
|
|
262
261
|
if (data.res) {
|
|
263
|
-
respond404(data.res, config
|
|
262
|
+
respond404(data.res, config);
|
|
264
263
|
}
|
|
265
264
|
else {
|
|
266
265
|
data.socket?.destroy();
|
|
@@ -514,7 +513,7 @@ export async function run(data) {
|
|
|
514
513
|
const filePath = config.const.ctrPath + pathLeft + '.js';
|
|
515
514
|
if (!await lFs.isFile(filePath)) {
|
|
516
515
|
// --- 指定的控制器不存在 ---
|
|
517
|
-
respond404(data.res, config
|
|
516
|
+
respond404(data.res, config);
|
|
518
517
|
return true;
|
|
519
518
|
}
|
|
520
519
|
// --- 加载控制器文件 ---
|
|
@@ -548,17 +547,16 @@ export async function run(data) {
|
|
|
548
547
|
data.res.end('');
|
|
549
548
|
return true;
|
|
550
549
|
}
|
|
551
|
-
// --- 检测 action 是否存在,以及排除内部方法 ---
|
|
552
|
-
if (pathRight.startsWith('_') || pathRight === 'onUpgrade' || pathRight === 'onLoad' || pathRight === 'onData' || pathRight === 'onDrain' || pathRight === 'onEnd' || pathRight === 'onClose' || pathRight === 'setPrototype' || pathRight === 'getPrototype' || pathRight === 'getAuthorization') {
|
|
553
|
-
// --- _ 开头的 action 是内部方法,不允许访问 ---
|
|
554
|
-
respond404(data.res, config, path);
|
|
555
|
-
return true;
|
|
556
|
-
}
|
|
557
550
|
pathRight = pathRight.replace(/-([a-zA-Z0-9])/g, function (t, t1) {
|
|
558
551
|
return t1.toUpperCase();
|
|
559
552
|
});
|
|
553
|
+
// --- 按实际调用名检查,框架基类及 Object 原型的成员不能作为 action ---
|
|
554
|
+
if (pathRight.startsWith('_') || pathRight in sCtr.Ctr.prototype) {
|
|
555
|
+
respond404(data.res, config);
|
|
556
|
+
return true;
|
|
557
|
+
}
|
|
560
558
|
if ((cctr[pathRight] === undefined) || (typeof cctr[pathRight] !== 'function')) {
|
|
561
|
-
respond404(data.res, config
|
|
559
|
+
respond404(data.res, config);
|
|
562
560
|
return true;
|
|
563
561
|
}
|
|
564
562
|
// --- 执行 onLoad 方法 ---
|
|
@@ -695,7 +693,7 @@ export async function run(data) {
|
|
|
695
693
|
lCore.writeHead(data.res, 500);
|
|
696
694
|
}
|
|
697
695
|
if (!data.res.writableEnded) {
|
|
698
|
-
data.res.end('<h1>500 Internal server error</h1
|
|
696
|
+
data.res.end('<h1>500 Internal server error</h1>');
|
|
699
697
|
}
|
|
700
698
|
}
|
|
701
699
|
else {
|
|
@@ -802,7 +800,7 @@ export async function run(data) {
|
|
|
802
800
|
lCore.writeHead(data.res, 500);
|
|
803
801
|
}
|
|
804
802
|
if (!data.res.writableEnded) {
|
|
805
|
-
data.res.end('<h1>500 Internal server error</h1
|
|
803
|
+
data.res.end('<h1>500 Internal server error</h1>');
|
|
806
804
|
}
|
|
807
805
|
}
|
|
808
806
|
await waitCtr(cctr ?? middle);
|
|
@@ -837,7 +835,7 @@ function getWsCtrName(path) {
|
|
|
837
835
|
*/
|
|
838
836
|
export async function unlinkUploadFiles(cctr) {
|
|
839
837
|
const cfiles = cctr instanceof sCtr.Ctr ? cctr.getPrototype('_files') : cctr;
|
|
840
|
-
for (const name
|
|
838
|
+
for (const name of Object.keys(cfiles)) {
|
|
841
839
|
let files = cfiles[name];
|
|
842
840
|
if (!Array.isArray(files)) {
|
|
843
841
|
files = [files];
|