@maiyunnet/kebab 3.1.20 → 3.2.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/index.d.ts +1 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/sys/child.js +2 -0
- package/sys/ctr.d.ts +2 -2
- package/sys/ctr.js +2 -2
- package/sys/route.js +16 -12
- package/www/example/ctr/middle.d.ts +1 -1
- package/www/example/ctr/middle.js +9 -6
- package/www/example/ctr/test.d.ts +0 -1
- package/www/example/ctr/test.js +0 -9
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
7
7
|
*/
|
|
8
8
|
/** --- 当前系统版本号 --- */
|
|
9
|
-
export const VER = '3.
|
|
9
|
+
export const VER = '3.2.0';
|
|
10
10
|
// --- 服务端用的路径 ---
|
|
11
11
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
12
12
|
/** --- /xxx/xxx --- */
|
package/package.json
CHANGED
package/sys/child.js
CHANGED
|
@@ -203,6 +203,8 @@ async function requestHandler(req, res, https) {
|
|
|
203
203
|
timer.timer = setTimeout(timer.callback, timer.timeout);
|
|
204
204
|
// --- 设置服务器名版本 ---
|
|
205
205
|
res.setHeader('Server', 'Kebab/' + kebab.VER);
|
|
206
|
+
res.setHeader('expires', 'Mon, 26 Jul 1994 05:00:00 GMT');
|
|
207
|
+
res.setHeader('cache-control', 'no-store');
|
|
206
208
|
// --- 当前 uri ---
|
|
207
209
|
let host = req.headers[':authority'];
|
|
208
210
|
if (host === undefined || typeof host !== 'string') {
|
package/sys/ctr.d.ts
CHANGED
|
@@ -128,8 +128,8 @@ export declare class Ctr {
|
|
|
128
128
|
* --- WebSocket 下连接被终止后会自动被调用的事件,可重写此方法 ---
|
|
129
129
|
*/
|
|
130
130
|
onClose(): void | Promise<void>;
|
|
131
|
-
/** --- 请求发送开始时调用,返回
|
|
132
|
-
onReqStart():
|
|
131
|
+
/** --- 请求发送开始时调用,返回 -1-流程中断,一般用于代理/反代,0-框架不会自动处理 post,1-自动处理(默认)(仅会在 middle 内触发) --- */
|
|
132
|
+
onReqStart(): number | Promise<number>;
|
|
133
133
|
/**
|
|
134
134
|
* --- 获取截止当前时间的总运行时间 ---
|
|
135
135
|
* @param ms 为 true 为毫秒,否则为秒
|
package/sys/ctr.js
CHANGED
|
@@ -169,9 +169,9 @@ export class Ctr {
|
|
|
169
169
|
onClose() {
|
|
170
170
|
return;
|
|
171
171
|
}
|
|
172
|
-
/** --- 请求发送开始时调用,返回
|
|
172
|
+
/** --- 请求发送开始时调用,返回 -1-流程中断,一般用于代理/反代,0-框架不会自动处理 post,1-自动处理(默认)(仅会在 middle 内触发) --- */
|
|
173
173
|
onReqStart() {
|
|
174
|
-
return
|
|
174
|
+
return 1;
|
|
175
175
|
}
|
|
176
176
|
/**
|
|
177
177
|
* --- 获取截止当前时间的总运行时间 ---
|
package/sys/route.js
CHANGED
|
@@ -31,15 +31,6 @@ export function clearKebabConfigs() {
|
|
|
31
31
|
* @param data 传导的数据
|
|
32
32
|
*/
|
|
33
33
|
export async function run(data) {
|
|
34
|
-
// --- 检测 path 是否是静态文件 ---
|
|
35
|
-
if (/^(stc\/.*|favicon.\w+?\??.*|apple[\w-]+?\.png\??.*|[\w-]+?\.txt\??.*|[\w-]+?\.html\??.*)/.test(data.path)) {
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
38
|
-
// --- 根据 res 还是 socket 进行初始化设置 ---
|
|
39
|
-
if (data.res) {
|
|
40
|
-
data.res.setHeader('expires', 'Mon, 26 Jul 1994 05:00:00 GMT');
|
|
41
|
-
data.res.setHeader('cache-control', 'no-store');
|
|
42
|
-
}
|
|
43
34
|
// --- 判断 kebab config 是否已经读取过 ---
|
|
44
35
|
if (!kebabConfigs[data.rootPath + 'kebab.json']) {
|
|
45
36
|
const configContent = await lFs.getContent(data.rootPath + 'kebab.json', 'utf8');
|
|
@@ -80,6 +71,7 @@ export async function run(data) {
|
|
|
80
71
|
// --- 加载 kebab config ---
|
|
81
72
|
const config = {};
|
|
82
73
|
const configData = kebabConfigs[data.rootPath + 'kebab.json'];
|
|
74
|
+
// --- 合并 configData 到 config ---
|
|
83
75
|
for (const name in configData) {
|
|
84
76
|
config[name] = configData[name];
|
|
85
77
|
}
|
|
@@ -123,9 +115,11 @@ export async function run(data) {
|
|
|
123
115
|
if (path === '') {
|
|
124
116
|
path = '@';
|
|
125
117
|
}
|
|
118
|
+
/** --- 不做语言跳转、不进入动态处理流程的路径 --- */
|
|
119
|
+
const stcPaths = /^(stc\/.*|favicon.\w+?\??.*|apple[\w-]+?\.png\??.*|[\w-]+?\.txt\??.*|[\w-]+?\.html\??.*)/;
|
|
126
120
|
// --- 检测是否托管语言页面 ---
|
|
127
121
|
const param = [];
|
|
128
|
-
if (config.lang && data.res) {
|
|
122
|
+
if (config.lang && data.res && !stcPaths.test(path)) {
|
|
129
123
|
// --- 仅仅 res 模式支持 config.lang ---
|
|
130
124
|
if (path[2] !== '/') {
|
|
131
125
|
// --- 不管是首页还是 @ 页,都会到此处(已经有语言目录不会到这里) ---
|
|
@@ -375,9 +369,19 @@ export async function run(data) {
|
|
|
375
369
|
middle.setPrototype('_action', pathRight);
|
|
376
370
|
middle.setPrototype('_headers', headers);
|
|
377
371
|
middle.setPrototype('_get', get);
|
|
378
|
-
/** --- 是否让框架自动获取 post,
|
|
372
|
+
/** --- 是否让框架自动获取 post,1 为自动(默认) --- */
|
|
379
373
|
const reqStartRtn = await middle.onReqStart();
|
|
380
|
-
if (reqStartRtn) {
|
|
374
|
+
if (reqStartRtn === -1) {
|
|
375
|
+
// --- 代理/反代了,什么也不管 ---
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
// --- 检测 path 是否是静态文件 ---
|
|
379
|
+
// --- 只能在这里做,因为 onReqStart 里面可能有反代,反代不能让 stc 等路径直连 ---
|
|
380
|
+
// --- 也得同时给反代走,所以 onReqStart 之后才能走到这一步判断 ---
|
|
381
|
+
if (stcPaths.test(data.path)) {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
if (reqStartRtn === 1) {
|
|
381
385
|
const rawPost = await getPost(data.req);
|
|
382
386
|
// --- 原始 POST ---
|
|
383
387
|
middle.setPrototype('_rawPost', rawPost.raw);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as kebab from '#kebab/index.js';
|
|
2
2
|
import * as sCtr from '#kebab/sys/ctr.js';
|
|
3
3
|
export default class extends sCtr.Ctr {
|
|
4
|
-
onReqStart():
|
|
4
|
+
onReqStart(): Promise<number>;
|
|
5
5
|
onLoad(): string | boolean;
|
|
6
6
|
onUnload(rtn: string | boolean | kebab.DbValue[]): string | boolean | kebab.DbValue[];
|
|
7
7
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
+
import * as lNet from '#kebab/lib/net.js';
|
|
1
2
|
import * as sCtr from '#kebab/sys/ctr.js';
|
|
2
3
|
export default class extends sCtr.Ctr {
|
|
3
|
-
onReqStart() {
|
|
4
|
-
if (this
|
|
5
|
-
|
|
4
|
+
async onReqStart() {
|
|
5
|
+
if (await lNet.rproxy(this, {
|
|
6
|
+
'test/net-rproxy/': 'https://cdn.jsdelivr.net/npm/deskrt@2.0.10/'
|
|
7
|
+
})) {
|
|
8
|
+
return -1;
|
|
6
9
|
}
|
|
7
|
-
if (this._config.const.path
|
|
8
|
-
return
|
|
10
|
+
if (this._config.const.path === 'test/net-mproxy1') {
|
|
11
|
+
return 0;
|
|
9
12
|
}
|
|
10
|
-
return
|
|
13
|
+
return 1;
|
|
11
14
|
}
|
|
12
15
|
onLoad() {
|
|
13
16
|
if (this._config.const.path !== 'test/middle') {
|
|
@@ -68,7 +68,6 @@ export default class extends sCtr.Ctr {
|
|
|
68
68
|
netReuse(): Promise<string>;
|
|
69
69
|
netError(): Promise<string>;
|
|
70
70
|
netHosts(): Promise<string>;
|
|
71
|
-
netRproxy(): Promise<string | boolean>;
|
|
72
71
|
netMproxy(): Promise<string | boolean>;
|
|
73
72
|
netMproxy1(): Promise<string | boolean>;
|
|
74
73
|
netFilterheaders(): string;
|
package/www/example/ctr/test.js
CHANGED
|
@@ -46,7 +46,6 @@ export default class extends sCtr.Ctr {
|
|
|
46
46
|
return true;
|
|
47
47
|
}
|
|
48
48
|
onReady() {
|
|
49
|
-
lCore.display('onReady');
|
|
50
49
|
return true;
|
|
51
50
|
}
|
|
52
51
|
onUnload(rtn) {
|
|
@@ -1776,14 +1775,6 @@ content: <pre>${lText.htmlescape((await res.getContent())?.toString() ?? '')}</p
|
|
|
1776
1775
|
error: <pre>${JSON.stringify(res.error, null, 4)}</pre>`);
|
|
1777
1776
|
return echo.join('') + this._getEnd();
|
|
1778
1777
|
}
|
|
1779
|
-
async netRproxy() {
|
|
1780
|
-
if (await lNet.rproxy(this, {
|
|
1781
|
-
'test/net-rproxy/': 'https://cdn.jsdelivr.net/npm/deskrt@2.0.10/'
|
|
1782
|
-
})) {
|
|
1783
|
-
return false;
|
|
1784
|
-
}
|
|
1785
|
-
return 'Nothing';
|
|
1786
|
-
}
|
|
1787
1778
|
async netMproxy() {
|
|
1788
1779
|
const echo = [];
|
|
1789
1780
|
const res = await lNet.get('https://cdn.jsdelivr.net/npm/deskrt@2.0.10/package.json', {
|