topbit 3.1.2 → 3.1.4
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/README.cn.md +0 -9
- package/README.md +0 -8
- package/demo/controller/__mid.js +1 -1
- package/demo/controller/api/test.js +46 -1
- package/demo/loader.js +1 -0
- package/docs/en/topbit-loader.md +4 -2
- package/docs/topbit-loader.md +6 -3
- package/package.json +1 -1
- package/src/loader/loader.js +10 -10
package/README.cn.md
CHANGED
|
@@ -1579,15 +1579,6 @@ app.run(1235)
|
|
|
1579
1579
|
|
|
1580
1580
|
---
|
|
1581
1581
|
|
|
1582
|
-
以下是根据你提供的 `titbit-toolkit` 原始文档内容,按照新的列表顺序重新整理的文档。
|
|
1583
|
-
|
|
1584
|
-
**注意**:
|
|
1585
|
-
* 根据指示,文档已针对新的 **Topbit** 框架语境进行了调整(即不再强调独立安装扩展)。
|
|
1586
|
-
* 列表中未包含的组件(如 `Timing`, `RealIP`, `MixLogger`, `SendType`, `SetFinal`, `Http2Limit`)已被移除。
|
|
1587
|
-
* 列表中包含但原文档未提供详细说明的组件(如 `SNI`),仅保留了描述占位符。
|
|
1588
|
-
|
|
1589
|
-
---
|
|
1590
|
-
|
|
1591
1582
|
### 1. Cors (跨域支持)
|
|
1592
1583
|
|
|
1593
1584
|
支持跨域请求的中间件。尽管是对跨域场景的支持,但在具备 `origin` 消息头的跨域通信和 `referer` 资源引入场景都做了支持,并且可以灵活选择和配置。
|
package/README.md
CHANGED
|
@@ -1543,14 +1543,6 @@ app.run(1235)
|
|
|
1543
1543
|
|
|
1544
1544
|
---
|
|
1545
1545
|
|
|
1546
|
-
The following documentation is reorganized based on the original `titbit-toolkit` documentation you provided, adapted for the new list order.
|
|
1547
|
-
|
|
1548
|
-
**Note**:
|
|
1549
|
-
* The documentation has been adjusted for the **Topbit** framework context (no longer emphasizing standalone installation of extensions).
|
|
1550
|
-
* Components not included in the list above have been removed.
|
|
1551
|
-
|
|
1552
|
-
---
|
|
1553
|
-
|
|
1554
1546
|
### 1. Cors (Cross-Origin Support)
|
|
1555
1547
|
|
|
1556
1548
|
Middleware that supports cross-origin requests. It supports cross-origin communication via the `origin` header as well as resource inclusion via `referer`, allowing for flexible selection and configuration.
|
package/demo/controller/__mid.js
CHANGED
|
@@ -11,6 +11,14 @@ class Test {
|
|
|
11
11
|
])
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
async post(ctx) {
|
|
15
|
+
ctx.ok(ctx.body)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
async list(ctx) {
|
|
19
|
+
ctx.ok(ctx.query)
|
|
20
|
+
}
|
|
21
|
+
|
|
14
22
|
__mid() {
|
|
15
23
|
return [
|
|
16
24
|
{
|
|
@@ -19,7 +27,44 @@ class Test {
|
|
|
19
27
|
await next(ctx)
|
|
20
28
|
console.log(`test ${ctx.method} end`)
|
|
21
29
|
}
|
|
22
|
-
}
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
{
|
|
33
|
+
middleware: async (ctx, next) => {
|
|
34
|
+
console.log('use for get list method')
|
|
35
|
+
await next(ctx)
|
|
36
|
+
console.log('end for get list method')
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
handler: [
|
|
40
|
+
'get', 'list'
|
|
41
|
+
]
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
{
|
|
45
|
+
middleware: async (ctx, next) => {
|
|
46
|
+
console.log('use for get method', (new Date).toLocaleString())
|
|
47
|
+
await next(ctx)
|
|
48
|
+
console.log('end for get method', (new Date).toLocaleString())
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
handler: [
|
|
52
|
+
'get'
|
|
53
|
+
]
|
|
54
|
+
},
|
|
55
|
+
|
|
56
|
+
{
|
|
57
|
+
middleware: async (ctx, next) => {
|
|
58
|
+
console.log(' -- use for post method', (new Date).toLocaleString())
|
|
59
|
+
ctx.body.tag = Math.random()
|
|
60
|
+
await next(ctx)
|
|
61
|
+
console.log(' -- end for post method', (new Date).toLocaleString())
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
handler: [
|
|
65
|
+
'post'
|
|
66
|
+
]
|
|
67
|
+
},
|
|
23
68
|
]
|
|
24
69
|
}
|
|
25
70
|
}
|
package/demo/loader.js
CHANGED
package/docs/en/topbit-loader.md
CHANGED
|
@@ -206,10 +206,12 @@ module.exports = [
|
|
|
206
206
|
|
|
207
207
|
```js
|
|
208
208
|
// Inside any controller file
|
|
209
|
-
|
|
209
|
+
__mid() {
|
|
210
210
|
return [
|
|
211
211
|
{ name: '@vip-auth', pre: true },
|
|
212
|
-
{ name: 'log', method: 'POST' }
|
|
212
|
+
{ name: 'log', method: 'POST' },
|
|
213
|
+
//use for controller method: get list
|
|
214
|
+
{ name: 'check', handler: ['get', 'list'] }
|
|
213
215
|
]
|
|
214
216
|
}
|
|
215
217
|
```
|
package/docs/topbit-loader.md
CHANGED
|
@@ -205,10 +205,13 @@ module.exports = [
|
|
|
205
205
|
|
|
206
206
|
```js
|
|
207
207
|
// 在 controller/user.js 中
|
|
208
|
-
|
|
208
|
+
// 只在本文件生效
|
|
209
|
+
__mid() {
|
|
209
210
|
return [
|
|
210
|
-
{ name: '@vip-auth', pre: true },
|
|
211
|
-
{ name: 'log', method: 'POST' }
|
|
211
|
+
{ name: '@vip-auth', pre: true },
|
|
212
|
+
{ name: 'log', method: 'POST' },
|
|
213
|
+
//只对控制器方法get list 启用中间件
|
|
214
|
+
{ name: 'check', handler: ['get', 'list'] }
|
|
212
215
|
]
|
|
213
216
|
}
|
|
214
217
|
```
|
package/package.json
CHANGED
package/src/loader/loader.js
CHANGED
|
@@ -56,7 +56,7 @@ class TopbitLoader {
|
|
|
56
56
|
multi: false,
|
|
57
57
|
optionsRoute: true,
|
|
58
58
|
fileAsGroup: true,
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
beforeController: null,
|
|
61
61
|
afterController: null,
|
|
62
62
|
|
|
@@ -566,22 +566,22 @@ class TopbitLoader {
|
|
|
566
566
|
let opts = { group };
|
|
567
567
|
f = `${this.config.prePath}${f}`;
|
|
568
568
|
|
|
569
|
-
if (!this.fileAsGroup && m.
|
|
570
|
-
m.
|
|
569
|
+
if (!this.config.fileAsGroup && m.handler === undefined) {
|
|
570
|
+
m.handler = [
|
|
571
571
|
'get', 'list', 'post', 'put', 'delete',
|
|
572
572
|
'options', 'patch', 'head', 'trace'
|
|
573
573
|
];
|
|
574
574
|
}
|
|
575
575
|
|
|
576
|
-
if (m.
|
|
576
|
+
if (m.handler && typeof m.handler === 'string') m.handler = [ m.handler ];
|
|
577
577
|
|
|
578
|
-
if (m.
|
|
578
|
+
if (m.handler && Array.isArray(m.handler)) {
|
|
579
579
|
opts.name = [];
|
|
580
|
-
let
|
|
581
|
-
for (let p of m.
|
|
582
|
-
|
|
583
|
-
if (
|
|
584
|
-
opts.name.push(`${f}/${
|
|
580
|
+
let handler_num;
|
|
581
|
+
for (let p of m.handler) {
|
|
582
|
+
handler_num = this.methodNumber[p.toLowerCase()];
|
|
583
|
+
if (handler_num === undefined) continue;
|
|
584
|
+
opts.name.push(`${f}/${handler_num}`);
|
|
585
585
|
}
|
|
586
586
|
}
|
|
587
587
|
|