@maiyunnet/kebab 3.2.0 → 3.2.2
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 +3 -1
- package/index.js +1 -1
- package/lib/core.d.ts +1 -0
- package/package.json +1 -1
- package/sys/child.js +11 -0
- package/sys/cmd.js +1 -0
- package/sys/route.js +10 -4
- package/www/example/ctr/test.js +3 -1
- package/www/example/ws/handler.d.ts +4 -0
- package/www/example/ws/handler.js +12 -0
package/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
6
6
|
*/
|
|
7
7
|
/** --- 当前系统版本号 --- */
|
|
8
|
-
export declare const VER = "3.2.
|
|
8
|
+
export declare const VER = "3.2.2";
|
|
9
9
|
/** --- 框架根目录,以 / 结尾 --- */
|
|
10
10
|
export declare const ROOT_PATH: string;
|
|
11
11
|
export declare const LIB_PATH: string;
|
|
@@ -134,6 +134,8 @@ export interface IConfigConst {
|
|
|
134
134
|
'path': string;
|
|
135
135
|
/** --- 不含 ? 开头 --- */
|
|
136
136
|
'qs': string;
|
|
137
|
+
/** --- 含 ? 开头 --- */
|
|
138
|
+
'qss': string;
|
|
137
139
|
'startTime': bigint;
|
|
138
140
|
'startMemory': number;
|
|
139
141
|
'mobile': boolean;
|
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
7
7
|
*/
|
|
8
8
|
/** --- 当前系统版本号 --- */
|
|
9
|
-
export const VER = '3.2.
|
|
9
|
+
export const VER = '3.2.2';
|
|
10
10
|
// --- 服务端用的路径 ---
|
|
11
11
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
12
12
|
/** --- /xxx/xxx --- */
|
package/lib/core.d.ts
CHANGED
package/package.json
CHANGED
package/sys/child.js
CHANGED
|
@@ -45,6 +45,17 @@ const linkCount = {};
|
|
|
45
45
|
async function run() {
|
|
46
46
|
// --- 加载 全局、vhosts、sni 证书 ---
|
|
47
47
|
await reload();
|
|
48
|
+
// --- 启动随带的 ind,如果独立运行 ind 则用 --ind 命令启动 ---
|
|
49
|
+
for (const ind of lCore.globalConfig.ind) {
|
|
50
|
+
if (!await lFs.isFile(kebab.IND_CWD + ind + '/index.js')) {
|
|
51
|
+
lCore.display('CHILD IND ERROR', 'IND FILE "' + ind + '" NOT FOUND.');
|
|
52
|
+
continue;
|
|
53
|
+
}
|
|
54
|
+
// --- 载入独立文件入口 ---
|
|
55
|
+
import((!kebab.IND_CWD.startsWith('/') ? '/' : '') + kebab.IND_CWD + ind + '/index.js').catch((e) => {
|
|
56
|
+
lCore.display('CHILD IND ERROR', ind, e);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
48
59
|
// --- 创建服务器并启动(支持 http2/https/http/websocket) ---
|
|
49
60
|
http2Server = http2.createSecureServer({
|
|
50
61
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
package/sys/cmd.js
CHANGED
package/sys/route.js
CHANGED
|
@@ -78,6 +78,7 @@ export async function run(data) {
|
|
|
78
78
|
config.const = {
|
|
79
79
|
'path': data.path,
|
|
80
80
|
'qs': data.uri.query ?? '',
|
|
81
|
+
'qss': data.uri.query ? '?' + data.uri.query : '',
|
|
81
82
|
'startTime': process.hrtime.bigint(),
|
|
82
83
|
'startMemory': process.memoryUsage().rss,
|
|
83
84
|
// --- 环境判断 ---
|
|
@@ -216,12 +217,17 @@ export async function run(data) {
|
|
|
216
217
|
/** --- 开发者返回值 --- */
|
|
217
218
|
let rtn;
|
|
218
219
|
if (data.socket && data.req instanceof http.IncomingMessage) {
|
|
219
|
-
// --- socket
|
|
220
|
-
|
|
220
|
+
// --- socket 模式 ---
|
|
221
|
+
// --- 判断真实控制器文件是否存在 ---
|
|
222
|
+
let filePath = config.const.wsPath + pathLeft + '.js';
|
|
221
223
|
if (!await lFs.isFile(filePath)) {
|
|
222
224
|
// --- 指定的控制器不存在 ---
|
|
223
|
-
|
|
224
|
-
|
|
225
|
+
filePath = config.const.wsPath + 'handler.js';
|
|
226
|
+
if (!await lFs.isFile(filePath)) {
|
|
227
|
+
// --- 默认 handler 也不存在 ---
|
|
228
|
+
data.socket?.destroy();
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
225
231
|
}
|
|
226
232
|
// --- 加载控制器文件 ---
|
|
227
233
|
const ctrCtr = (await import((!filePath.startsWith('/') ? '/' : '') + filePath)).default;
|
package/www/example/ctr/test.js
CHANGED
|
@@ -193,6 +193,7 @@ export default class extends sCtr.Ctr {
|
|
|
193
193
|
'<br><br><b>Ws:</b>',
|
|
194
194
|
`<br><br><a href="${this._config.const.urlBase}test/ws-server">View "test/ws-server"</a>`,
|
|
195
195
|
`<br><a href="${this._config.const.urlBase}test/ws-server?ac=rproxy">View ws rproxy</a>`,
|
|
196
|
+
`<br><a href="${this._config.const.urlBase}test/ws-server?ac=rproxy2">View ws rproxy2 (handler)</a>`,
|
|
196
197
|
`<br><a href="${this._config.const.urlBase}test/ws-client">View "test/ws-client"</a>`,
|
|
197
198
|
`<br><a href="${this._config.const.urlBase}test/ws-client?ac=mproxy">View ws mproxy</a>`,
|
|
198
199
|
'<br><br><b>Ssh:</b>',
|
|
@@ -2692,6 +2693,7 @@ ${lTime.format(null, 'd|D|j|l|N|w|Y|y|F|M|m|H|h|i|s|T')}`;
|
|
|
2692
2693
|
wsServer() {
|
|
2693
2694
|
const echo = '<a href="' + this._config.const.urlBase + 'test/ws-server">Default</a> | ' +
|
|
2694
2695
|
'<a href="' + this._config.const.urlBase + 'test/ws-server?ac=rproxy">rproxy</a> | ' +
|
|
2696
|
+
'<a href="' + this._config.const.urlBase + 'test/ws-server?ac=rproxy2">rproxy2</a> | ' +
|
|
2695
2697
|
'<a href="' + this._config.const.urlBase + 'test">Return</a><br><br>' +
|
|
2696
2698
|
`Nick: <input id="nick"> <input id="btn" type="button" value="Enter" onclick="enter()"> <input id="stop" type="button" value="Stop" onclick="stop()" disabled>
|
|
2697
2699
|
<div id="list" style="border: solid 1px #000; line-height: 1.5; height: 300px; overflow-y: scroll; margin-top: 10px; padding: 10px;"></div>
|
|
@@ -2724,7 +2726,7 @@ function enter() {
|
|
|
2724
2726
|
nickEl.disabled = true;
|
|
2725
2727
|
btnEl.disabled = true;
|
|
2726
2728
|
listEl.insertAdjacentHTML('afterbegin', '<div>[' + dateStr() + '] Connecting...</div>');
|
|
2727
|
-
ws = new WebSocket('ws${this._config.const.https ? 's' : ''}://${this._config.const.host}/${this._get['ac'] === 'rproxy' ? '
|
|
2729
|
+
ws = new WebSocket('ws${this._config.const.https ? 's' : ''}://${this._config.const.host}/${(this._get['ac'] === 'rproxy' || this._get['ac'] === 'rproxy2') ? this._get['ac'] : 'test'}');
|
|
2728
2730
|
ws.onopen = function() {
|
|
2729
2731
|
listEl.insertAdjacentHTML('afterbegin', '<div>[' + dateStr() + '] Event: onOpen.</div>');
|
|
2730
2732
|
ws.send('Hello: ' + nick);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as sCtr from '#kebab/sys/ctr.js';
|
|
2
|
+
import * as lCore from '#kebab/lib/core.js';
|
|
3
|
+
import * as lWs from '#kebab/lib/ws.js';
|
|
4
|
+
export default class extends sCtr.Ctr {
|
|
5
|
+
async onLoad() {
|
|
6
|
+
lCore.debug('WebSocket handle test onLoad.');
|
|
7
|
+
if (this._config.const.path === 'rproxy2') {
|
|
8
|
+
await lWs.rproxy(this, `ws${this._config.const.https ? 's' : ''}://${this._config.const.host}/test`);
|
|
9
|
+
}
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|