@maiyunnet/kebab 9.11.7 → 9.11.9
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 +67 -36
- package/index.d.ts +1 -1
- package/index.js +1 -1
- package/lib/undici/response.d.ts +1 -1
- package/lib/undici.d.ts +17 -1
- package/lib/undici.js +26 -6
- package/package.json +1 -1
package/doc/kebab-rag.md
CHANGED
|
@@ -1360,7 +1360,7 @@ index/variables/VER.md
|
|
|
1360
1360
|
|
|
1361
1361
|
# Variable: VER
|
|
1362
1362
|
|
|
1363
|
-
> `const` **VER**: `"9.11.
|
|
1363
|
+
> `const` **VER**: `"9.11.9"` = `'9.11.9'`
|
|
1364
1364
|
|
|
1365
1365
|
Defined in: [index.ts:10](https://github.com/maiyunnet/kebab/blob/master/index.ts#L10)
|
|
1366
1366
|
|
|
@@ -18524,9 +18524,20 @@ lib/undici/functions/rproxy.md
|
|
|
18524
18524
|
|
|
18525
18525
|
> **rproxy**(`ctr`, `route`, `opt?`): `Promise`\<`boolean`\>
|
|
18526
18526
|
|
|
18527
|
-
Defined in: [lib/undici.ts:
|
|
18527
|
+
Defined in: [lib/undici.ts:649](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L649)
|
|
18528
18528
|
|
|
18529
|
-
|
|
18529
|
+
反向代理,将本服务器的某个路由反代到其他网址
|
|
18530
|
+
|
|
18531
|
+
## 使用方式
|
|
18532
|
+
|
|
18533
|
+
### 方式 1:在 onReqStart 中调用(完全反代)
|
|
18534
|
+
请求体未被消费,POST body 会完整转发到上游。
|
|
18535
|
+
|
|
18536
|
+
### 方式 2:在控制器方法中调用(按需反代)
|
|
18537
|
+
此时可复用控制器的私有方法做前置处理:
|
|
18538
|
+
- 如果 req 流尚未消费,body 会自动转发。
|
|
18539
|
+
- 如果 req 流已消费,可通过 opt.body 手动传入请求体。
|
|
18540
|
+
- opt.body 优先级高于 req 流。
|
|
18530
18541
|
|
|
18531
18542
|
## Parameters
|
|
18532
18543
|
|
|
@@ -18601,7 +18612,7 @@ lib/undici/interfaces/IMproxyOptions.md
|
|
|
18601
18612
|
|
|
18602
18613
|
# Interface: IMproxyOptions
|
|
18603
18614
|
|
|
18604
|
-
Defined in: [lib/undici.ts:
|
|
18615
|
+
Defined in: [lib/undici.ts:743](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L743)
|
|
18605
18616
|
|
|
18606
18617
|
正向代理请求的传入参数选项
|
|
18607
18618
|
|
|
@@ -18611,7 +18622,7 @@ Defined in: [lib/undici.ts:723](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18611
18622
|
|
|
18612
18623
|
> `optional` **filter?**: (`h`) => `boolean`
|
|
18613
18624
|
|
|
18614
|
-
Defined in: [lib/undici.ts:
|
|
18625
|
+
Defined in: [lib/undici.ts:752](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L752)
|
|
18615
18626
|
|
|
18616
18627
|
过滤 header,返回 true 则留下
|
|
18617
18628
|
|
|
@@ -18631,7 +18642,7 @@ Defined in: [lib/undici.ts:732](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18631
18642
|
|
|
18632
18643
|
> `optional` **follow?**: `number`
|
|
18633
18644
|
|
|
18634
|
-
Defined in: [lib/undici.ts:
|
|
18645
|
+
Defined in: [lib/undici.ts:746](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L746)
|
|
18635
18646
|
|
|
18636
18647
|
***
|
|
18637
18648
|
|
|
@@ -18639,7 +18650,7 @@ Defined in: [lib/undici.ts:726](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18639
18650
|
|
|
18640
18651
|
> `optional` **headers?**: [`THttpHeaders`](../type-aliases/THttpHeaders.md)
|
|
18641
18652
|
|
|
18642
|
-
Defined in: [lib/undici.ts:
|
|
18653
|
+
Defined in: [lib/undici.ts:750](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L750)
|
|
18643
18654
|
|
|
18644
18655
|
***
|
|
18645
18656
|
|
|
@@ -18647,7 +18658,7 @@ Defined in: [lib/undici.ts:730](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18647
18658
|
|
|
18648
18659
|
> `optional` **hosts?**: `string` \| `Record`\<`string`, `string`\>
|
|
18649
18660
|
|
|
18650
|
-
Defined in: [lib/undici.ts:
|
|
18661
|
+
Defined in: [lib/undici.ts:748](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L748)
|
|
18651
18662
|
|
|
18652
18663
|
自定义 host 映射,如 {'www.maiyun.net': '127.0.0.1'},或全部映射到一个 host
|
|
18653
18664
|
|
|
@@ -18657,7 +18668,7 @@ Defined in: [lib/undici.ts:728](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18657
18668
|
|
|
18658
18669
|
> `optional` **local?**: `string`
|
|
18659
18670
|
|
|
18660
|
-
Defined in: [lib/undici.ts:
|
|
18671
|
+
Defined in: [lib/undici.ts:749](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L749)
|
|
18661
18672
|
|
|
18662
18673
|
***
|
|
18663
18674
|
|
|
@@ -18665,7 +18676,7 @@ Defined in: [lib/undici.ts:729](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18665
18676
|
|
|
18666
18677
|
> `optional` **reuse?**: `string` \| `Agent` \| `ProxyAgent`
|
|
18667
18678
|
|
|
18668
|
-
Defined in: [lib/undici.ts:
|
|
18679
|
+
Defined in: [lib/undici.ts:754](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L754)
|
|
18669
18680
|
|
|
18670
18681
|
默认为 default
|
|
18671
18682
|
|
|
@@ -18675,7 +18686,7 @@ Defined in: [lib/undici.ts:734](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18675
18686
|
|
|
18676
18687
|
> `optional` **timeout?**: `number`
|
|
18677
18688
|
|
|
18678
|
-
Defined in: [lib/undici.ts:
|
|
18689
|
+
Defined in: [lib/undici.ts:745](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L745)
|
|
18679
18690
|
|
|
18680
18691
|
秒数,默认 300 秒
|
|
18681
18692
|
|
|
@@ -18690,7 +18701,7 @@ lib/undici/interfaces/IRequestOptions.md
|
|
|
18690
18701
|
|
|
18691
18702
|
# Interface: IRequestOptions
|
|
18692
18703
|
|
|
18693
|
-
Defined in: [lib/undici.ts:
|
|
18704
|
+
Defined in: [lib/undici.ts:710](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L710)
|
|
18694
18705
|
|
|
18695
18706
|
请求的传入参数选项
|
|
18696
18707
|
|
|
@@ -18700,7 +18711,7 @@ Defined in: [lib/undici.ts:690](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18700
18711
|
|
|
18701
18712
|
> `optional` **cookie?**: `Record`\<`string`, [`ICookie`](../../cookie/interfaces/ICookie.md)\>
|
|
18702
18713
|
|
|
18703
|
-
Defined in: [lib/undici.ts:
|
|
18714
|
+
Defined in: [lib/undici.ts:735](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L735)
|
|
18704
18715
|
|
|
18705
18716
|
cookie 托管对象
|
|
18706
18717
|
|
|
@@ -18710,7 +18721,7 @@ cookie 托管对象
|
|
|
18710
18721
|
|
|
18711
18722
|
> `optional` **follow?**: `number`
|
|
18712
18723
|
|
|
18713
|
-
Defined in: [lib/undici.ts:
|
|
18724
|
+
Defined in: [lib/undici.ts:716](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L716)
|
|
18714
18725
|
|
|
18715
18726
|
追踪 location 次数,0 为不追踪,默认为 0
|
|
18716
18727
|
|
|
@@ -18720,7 +18731,7 @@ Defined in: [lib/undici.ts:696](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18720
18731
|
|
|
18721
18732
|
> `optional` **headers?**: [`THttpHeaders`](../type-aliases/THttpHeaders.md)
|
|
18722
18733
|
|
|
18723
|
-
Defined in: [lib/undici.ts:
|
|
18734
|
+
Defined in: [lib/undici.ts:721](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L721)
|
|
18724
18735
|
|
|
18725
18736
|
***
|
|
18726
18737
|
|
|
@@ -18728,7 +18739,7 @@ Defined in: [lib/undici.ts:701](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18728
18739
|
|
|
18729
18740
|
> `optional` **hosts?**: `string` \| `Record`\<`string`, `string`\>
|
|
18730
18741
|
|
|
18731
|
-
Defined in: [lib/undici.ts:
|
|
18742
|
+
Defined in: [lib/undici.ts:718](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L718)
|
|
18732
18743
|
|
|
18733
18744
|
自定义 host 映射,如 {'www.maiyun.net': '127.0.0.1'},或全部映射到一个 host
|
|
18734
18745
|
|
|
@@ -18738,7 +18749,7 @@ Defined in: [lib/undici.ts:698](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18738
18749
|
|
|
18739
18750
|
> `optional` **keep?**: `boolean`
|
|
18740
18751
|
|
|
18741
|
-
Defined in: [lib/undici.ts:
|
|
18752
|
+
Defined in: [lib/undici.ts:731](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L731)
|
|
18742
18753
|
|
|
18743
18754
|
连接是否保持长连接(即是否允许复用),默认为 true
|
|
18744
18755
|
|
|
@@ -18748,7 +18759,7 @@ Defined in: [lib/undici.ts:711](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18748
18759
|
|
|
18749
18760
|
> `optional` **local?**: `string`
|
|
18750
18761
|
|
|
18751
|
-
Defined in: [lib/undici.ts:
|
|
18762
|
+
Defined in: [lib/undici.ts:720](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L720)
|
|
18752
18763
|
|
|
18753
18764
|
***
|
|
18754
18765
|
|
|
@@ -18756,7 +18767,7 @@ Defined in: [lib/undici.ts:700](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18756
18767
|
|
|
18757
18768
|
> `optional` **log?**: `boolean`
|
|
18758
18769
|
|
|
18759
|
-
Defined in: [lib/undici.ts:
|
|
18770
|
+
Defined in: [lib/undici.ts:737](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L737)
|
|
18760
18771
|
|
|
18761
18772
|
若有异常写入文件日志,默认为 true
|
|
18762
18773
|
|
|
@@ -18766,7 +18777,7 @@ Defined in: [lib/undici.ts:717](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18766
18777
|
|
|
18767
18778
|
> `optional` **method?**: `"GET"` \| `"POST"` \| `"PUT"` \| `"DELETE"` \| `"OPTIONS"`
|
|
18768
18779
|
|
|
18769
|
-
Defined in: [lib/undici.ts:
|
|
18780
|
+
Defined in: [lib/undici.ts:711](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L711)
|
|
18770
18781
|
|
|
18771
18782
|
***
|
|
18772
18783
|
|
|
@@ -18774,7 +18785,7 @@ Defined in: [lib/undici.ts:691](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18774
18785
|
|
|
18775
18786
|
> `optional` **mproxy?**: `object`
|
|
18776
18787
|
|
|
18777
|
-
Defined in: [lib/undici.ts:
|
|
18788
|
+
Defined in: [lib/undici.ts:723](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L723)
|
|
18778
18789
|
|
|
18779
18790
|
正向 mproxy 代理,url 如 https://xxx/abc
|
|
18780
18791
|
|
|
@@ -18802,7 +18813,7 @@ Defined in: [lib/undici.ts:703](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18802
18813
|
|
|
18803
18814
|
> `optional` **reuse?**: `string` \| `Agent` \| `ProxyAgent`
|
|
18804
18815
|
|
|
18805
|
-
Defined in: [lib/undici.ts:
|
|
18816
|
+
Defined in: [lib/undici.ts:733](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L733)
|
|
18806
18817
|
|
|
18807
18818
|
复用池名/Agent,默认为 default
|
|
18808
18819
|
|
|
@@ -18812,7 +18823,7 @@ Defined in: [lib/undici.ts:713](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18812
18823
|
|
|
18813
18824
|
> `optional` **save?**: `string`
|
|
18814
18825
|
|
|
18815
|
-
Defined in: [lib/undici.ts:
|
|
18826
|
+
Defined in: [lib/undici.ts:719](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L719)
|
|
18816
18827
|
|
|
18817
18828
|
***
|
|
18818
18829
|
|
|
@@ -18820,7 +18831,7 @@ Defined in: [lib/undici.ts:699](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18820
18831
|
|
|
18821
18832
|
> `optional` **signal?**: `AbortSignal`
|
|
18822
18833
|
|
|
18823
|
-
Defined in: [lib/undici.ts:
|
|
18834
|
+
Defined in: [lib/undici.ts:739](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L739)
|
|
18824
18835
|
|
|
18825
18836
|
请求中止信号
|
|
18826
18837
|
|
|
@@ -18830,7 +18841,7 @@ Defined in: [lib/undici.ts:719](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18830
18841
|
|
|
18831
18842
|
> `optional` **timeout?**: `number`
|
|
18832
18843
|
|
|
18833
|
-
Defined in: [lib/undici.ts:
|
|
18844
|
+
Defined in: [lib/undici.ts:714](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L714)
|
|
18834
18845
|
|
|
18835
18846
|
秒数,默认 300 秒
|
|
18836
18847
|
|
|
@@ -18840,7 +18851,7 @@ Defined in: [lib/undici.ts:694](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18840
18851
|
|
|
18841
18852
|
> `optional` **type?**: `"form"` \| `"json"`
|
|
18842
18853
|
|
|
18843
|
-
Defined in: [lib/undici.ts:
|
|
18854
|
+
Defined in: [lib/undici.ts:712](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L712)
|
|
18844
18855
|
|
|
18845
18856
|
lib/undici/interfaces/IRproxyOptions.md
|
|
18846
18857
|
---
|
|
@@ -18853,17 +18864,27 @@ lib/undici/interfaces/IRproxyOptions.md
|
|
|
18853
18864
|
|
|
18854
18865
|
# Interface: IRproxyOptions
|
|
18855
18866
|
|
|
18856
|
-
Defined in: [lib/undici.ts:
|
|
18867
|
+
Defined in: [lib/undici.ts:758](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L758)
|
|
18857
18868
|
|
|
18858
18869
|
反向代理请求的传入参数选项
|
|
18859
18870
|
|
|
18860
18871
|
## Properties
|
|
18861
18872
|
|
|
18873
|
+
### body?
|
|
18874
|
+
|
|
18875
|
+
> `optional` **body?**: `string` \| `Buffer`\<`ArrayBufferLike`\> \| `Readable`
|
|
18876
|
+
|
|
18877
|
+
Defined in: [lib/undici.ts:777](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L777)
|
|
18878
|
+
|
|
18879
|
+
手动传入请求体(优先于原始 req 流),用于 req 流已消费后仍需转发 body 的场景
|
|
18880
|
+
|
|
18881
|
+
***
|
|
18882
|
+
|
|
18862
18883
|
### filter?
|
|
18863
18884
|
|
|
18864
18885
|
> `optional` **filter?**: (`h`) => `boolean`
|
|
18865
18886
|
|
|
18866
|
-
Defined in: [lib/undici.ts:
|
|
18887
|
+
Defined in: [lib/undici.ts:767](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L767)
|
|
18867
18888
|
|
|
18868
18889
|
过滤 header,返回 true 则留下
|
|
18869
18890
|
|
|
@@ -18883,7 +18904,7 @@ Defined in: [lib/undici.ts:747](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18883
18904
|
|
|
18884
18905
|
> `optional` **follow?**: `number`
|
|
18885
18906
|
|
|
18886
|
-
Defined in: [lib/undici.ts:
|
|
18907
|
+
Defined in: [lib/undici.ts:761](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L761)
|
|
18887
18908
|
|
|
18888
18909
|
***
|
|
18889
18910
|
|
|
@@ -18891,7 +18912,7 @@ Defined in: [lib/undici.ts:741](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18891
18912
|
|
|
18892
18913
|
> `optional` **headers?**: [`THttpHeaders`](../type-aliases/THttpHeaders.md)
|
|
18893
18914
|
|
|
18894
|
-
Defined in: [lib/undici.ts:
|
|
18915
|
+
Defined in: [lib/undici.ts:765](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L765)
|
|
18895
18916
|
|
|
18896
18917
|
***
|
|
18897
18918
|
|
|
@@ -18899,7 +18920,7 @@ Defined in: [lib/undici.ts:745](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18899
18920
|
|
|
18900
18921
|
> `optional` **hosts?**: `string` \| `Record`\<`string`, `string`\>
|
|
18901
18922
|
|
|
18902
|
-
Defined in: [lib/undici.ts:
|
|
18923
|
+
Defined in: [lib/undici.ts:763](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L763)
|
|
18903
18924
|
|
|
18904
18925
|
自定义 host 映射,如 {'www.maiyun.net': '127.0.0.1'},或全部映射到一个 host
|
|
18905
18926
|
|
|
@@ -18909,7 +18930,7 @@ Defined in: [lib/undici.ts:743](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18909
18930
|
|
|
18910
18931
|
> `optional` **local?**: `string`
|
|
18911
18932
|
|
|
18912
|
-
Defined in: [lib/undici.ts:
|
|
18933
|
+
Defined in: [lib/undici.ts:764](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L764)
|
|
18913
18934
|
|
|
18914
18935
|
***
|
|
18915
18936
|
|
|
@@ -18917,7 +18938,7 @@ Defined in: [lib/undici.ts:744](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18917
18938
|
|
|
18918
18939
|
> `optional` **mproxy?**: `object`
|
|
18919
18940
|
|
|
18920
|
-
Defined in: [lib/undici.ts:
|
|
18941
|
+
Defined in: [lib/undici.ts:769](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L769)
|
|
18921
18942
|
|
|
18922
18943
|
正向 mproxy 代理,url 如 https://xxx/abc
|
|
18923
18944
|
|
|
@@ -18941,11 +18962,21 @@ Defined in: [lib/undici.ts:749](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18941
18962
|
|
|
18942
18963
|
***
|
|
18943
18964
|
|
|
18965
|
+
### querys?
|
|
18966
|
+
|
|
18967
|
+
> `optional` **querys?**: `Record`\<`string`, `any`\>
|
|
18968
|
+
|
|
18969
|
+
Defined in: [lib/undici.ts:779](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L779)
|
|
18970
|
+
|
|
18971
|
+
自定义 GET 查询参数,传入后直接替换代理目标 URL 的整个 query string
|
|
18972
|
+
|
|
18973
|
+
***
|
|
18974
|
+
|
|
18944
18975
|
### reuse?
|
|
18945
18976
|
|
|
18946
18977
|
> `optional` **reuse?**: `string` \| `Agent` \| `ProxyAgent`
|
|
18947
18978
|
|
|
18948
|
-
Defined in: [lib/undici.ts:
|
|
18979
|
+
Defined in: [lib/undici.ts:781](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L781)
|
|
18949
18980
|
|
|
18950
18981
|
默认为 default
|
|
18951
18982
|
|
|
@@ -18955,7 +18986,7 @@ Defined in: [lib/undici.ts:757](https://github.com/maiyunnet/kebab/blob/master/l
|
|
|
18955
18986
|
|
|
18956
18987
|
> `optional` **timeout?**: `number`
|
|
18957
18988
|
|
|
18958
|
-
Defined in: [lib/undici.ts:
|
|
18989
|
+
Defined in: [lib/undici.ts:760](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L760)
|
|
18959
18990
|
|
|
18960
18991
|
秒数,默认 300 秒
|
|
18961
18992
|
|
|
@@ -19444,7 +19475,7 @@ lib/undici/type-aliases/THttpHeaders.md
|
|
|
19444
19475
|
|
|
19445
19476
|
> **THttpHeaders** = `http.IncomingHttpHeaders` & `object`
|
|
19446
19477
|
|
|
19447
|
-
Defined in: [lib/undici.ts:
|
|
19478
|
+
Defined in: [lib/undici.ts:786](https://github.com/maiyunnet/kebab/blob/master/lib/undici.ts#L786)
|
|
19448
19479
|
|
|
19449
19480
|
http headers
|
|
19450
19481
|
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* --- 本文件用来定义每个目录实体地址的常量 ---
|
|
7
7
|
*/
|
|
8
8
|
/** --- 当前系统版本号 --- */
|
|
9
|
-
export const VER = '9.11.
|
|
9
|
+
export const VER = '9.11.9';
|
|
10
10
|
// --- 服务端用的路径 ---
|
|
11
11
|
const imu = decodeURIComponent(import.meta.url).replace('file://', '').replace(/^\/(\w:)/, '$1');
|
|
12
12
|
/** --- /xxx/xxx --- */
|
package/lib/undici/response.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export declare class Response {
|
|
|
31
31
|
/**
|
|
32
32
|
* --- 获取响应读取流对象 ---
|
|
33
33
|
*/
|
|
34
|
-
getStream():
|
|
34
|
+
getStream(): (import("undici/types/readable").default & undici.Dispatcher.BodyMixin) | zlib.Gunzip | zlib.Inflate | zlib.BrotliDecompress | null;
|
|
35
35
|
/**
|
|
36
36
|
* --- 获取原生响应读取流对象 ---
|
|
37
37
|
*/
|
package/lib/undici.d.ts
CHANGED
|
@@ -94,7 +94,19 @@ export declare function mproxy(ctr: sCtr.Ctr, auth: string, opt?: IMproxyOptions
|
|
|
94
94
|
*/
|
|
95
95
|
export declare function mproxyData(ctr: sCtr.Ctr): kebab.Json;
|
|
96
96
|
/**
|
|
97
|
-
* ---
|
|
97
|
+
* --- 反向代理,将本服务器的某个路由反代到其他网址 ---
|
|
98
|
+
*
|
|
99
|
+
* ## 使用方式
|
|
100
|
+
*
|
|
101
|
+
* ### 方式 1:在 onReqStart 中调用(完全反代)
|
|
102
|
+
* 请求体未被消费,POST body 会完整转发到上游。
|
|
103
|
+
*
|
|
104
|
+
* ### 方式 2:在控制器方法中调用(按需反代)
|
|
105
|
+
* 此时可复用控制器的私有方法做前置处理:
|
|
106
|
+
* - 如果 req 流尚未消费,body 会自动转发。
|
|
107
|
+
* - 如果 req 流已消费,可通过 opt.body 手动传入请求体。
|
|
108
|
+
* - opt.body 优先级高于 req 流。
|
|
109
|
+
*
|
|
98
110
|
* @param ctr 当前控制器
|
|
99
111
|
* @param route 要反代的路由
|
|
100
112
|
* @param opt 参数
|
|
@@ -165,6 +177,10 @@ export interface IRproxyOptions {
|
|
|
165
177
|
/** --- 落地端自定义 host 映射,如 {'www.maiyun.net': '127.0.0.1'},或全部映射到一个 host --- */
|
|
166
178
|
'hosts'?: Record<string, string> | string;
|
|
167
179
|
};
|
|
180
|
+
/** --- 手动传入请求体(优先于原始 req 流),用于 req 流已消费后仍需转发 body 的场景 --- */
|
|
181
|
+
'body'?: Buffer | string | stream.Readable;
|
|
182
|
+
/** --- 自定义 GET 查询参数,传入后直接替换代理目标 URL 的整个 query string --- */
|
|
183
|
+
'querys'?: Record<string, any>;
|
|
168
184
|
/** --- 默认为 default --- */
|
|
169
185
|
'reuse'?: string | undici.ProxyAgent | undici.Agent;
|
|
170
186
|
}
|
package/lib/undici.js
CHANGED
|
@@ -560,7 +560,19 @@ export function mproxyData(ctr) {
|
|
|
560
560
|
return data;
|
|
561
561
|
}
|
|
562
562
|
/**
|
|
563
|
-
* ---
|
|
563
|
+
* --- 反向代理,将本服务器的某个路由反代到其他网址 ---
|
|
564
|
+
*
|
|
565
|
+
* ## 使用方式
|
|
566
|
+
*
|
|
567
|
+
* ### 方式 1:在 onReqStart 中调用(完全反代)
|
|
568
|
+
* 请求体未被消费,POST body 会完整转发到上游。
|
|
569
|
+
*
|
|
570
|
+
* ### 方式 2:在控制器方法中调用(按需反代)
|
|
571
|
+
* 此时可复用控制器的私有方法做前置处理:
|
|
572
|
+
* - 如果 req 流尚未消费,body 会自动转发。
|
|
573
|
+
* - 如果 req 流已消费,可通过 opt.body 手动传入请求体。
|
|
574
|
+
* - opt.body 优先级高于 req 流。
|
|
575
|
+
*
|
|
564
576
|
* @param ctr 当前控制器
|
|
565
577
|
* @param route 要反代的路由
|
|
566
578
|
* @param opt 参数
|
|
@@ -570,9 +582,6 @@ export async function rproxy(ctr, route, opt = {}) {
|
|
|
570
582
|
const res = ctr.getPrototype('_res');
|
|
571
583
|
const config = ctr.getPrototype('_config');
|
|
572
584
|
const path = config.const.path + (config.const.qs ? '?' + config.const.qs : '');
|
|
573
|
-
if (req.readableEnded) {
|
|
574
|
-
return false;
|
|
575
|
-
}
|
|
576
585
|
for (const key in route) {
|
|
577
586
|
if (!path.startsWith(key)) {
|
|
578
587
|
continue;
|
|
@@ -585,8 +594,19 @@ export async function rproxy(ctr, route, opt = {}) {
|
|
|
585
594
|
opt.method = req.method ?? 'GET';
|
|
586
595
|
opt.headers ??= {};
|
|
587
596
|
const headers = Object.assign(filterHeaders(req.headers, undefined, opt.filter), opt.headers);
|
|
588
|
-
// ---
|
|
589
|
-
|
|
597
|
+
// --- 拼接代理目标 URL ---
|
|
598
|
+
let proxyUrl = route[key] + lpath;
|
|
599
|
+
// --- 自定义 GET 查询参数(直接替换整个 query string) ---
|
|
600
|
+
if (opt.querys) {
|
|
601
|
+
const parsed = lText.parseUrl(proxyUrl);
|
|
602
|
+
const newQueryStr = lText.queryStringify(opt.querys);
|
|
603
|
+
const prefix = parsed.protocol
|
|
604
|
+
? parsed.protocol + '//' + (parsed.host ?? '') + parsed.pathname
|
|
605
|
+
: parsed.pathname;
|
|
606
|
+
proxyUrl = prefix + (newQueryStr ? '?' + newQueryStr : '') + (parsed.hash ? '#' + parsed.hash : '');
|
|
607
|
+
}
|
|
608
|
+
// --- 发起请求(opt.body 优先于原始 req 流) ---
|
|
609
|
+
const rres = await request(proxyUrl, opt.body ?? req, {
|
|
590
610
|
...opt,
|
|
591
611
|
headers,
|
|
592
612
|
});
|