Skip to content

Commit a15b5e4

Browse files
committed
add document of proxy
1 parent e9d7026 commit a15b5e4

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

docs/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
: > ./readme.md
55

66
# merge all doc.md to readme.md doc by this order
7-
for md in intro edit mock group authority list push keymap faq
7+
for md in intro edit mock proxy group authority list push keymap faq
88
do
99
( cat ${md}.md; echo ) >> ./readme.md
1010
done

docs/proxy.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
## 关于代理
2+
3+
api-mocker支持代理mock请求到**线上地址**或者**测试地址**,前提是已经在接口设置中配置对应的地址链接,且为绝对路径。
4+
5+
### 开启代理的两种方法
6+
7+
1. 在接口编辑页左侧的 [**代理转发**] 选项勾选对应的转发规则。
8+
2. 可以在请求Mock URL时,带上query参数来设置:
9+
- 转发线上:{ mockURL }?_mockProxyStatus=1
10+
- 转发测试:{ mockURL }?_mockProxyStatus=2
11+
12+
### 代理鉴权
13+
14+
有些接口需要cookie鉴权,而mock地址与线上、测试地址并非同个域名,所以cookie没办法共通。为此api-mocker提供一个配置:mock请求的请求头若设置了字段`api-cookie`,则会使用此字段的值作为代理请求的`cookie`
15+
16+
故开发阶段可以将某个已鉴权cookie,写至mock请求头的`api-cookie`字段,如示例:
17+
```javascript
18+
$.ajax({
19+
url: mockUrl,
20+
method: 'get',
21+
headers: {
22+
'api-coookie': 'your cookie of authentication'
23+
}
24+
})
25+
```
26+
27+
亦或者直接手动将该`cookie`设置到mock请求的域名下,mock服务端会将当前域名的cookie转发到代理请求地址。
28+
29+
> 注:若请求头设置了`api-cookie`,则不会再使用mock请求地址的原本cookie。

docs/readme.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,36 @@ Schema = {
125125
### 建议
126126
* 如果对于假数据随机性要求不高,不建议写mock语法,也不需要填写`Schema``Example`,系统会自动生成假数据。
127127

128+
## 关于代理
129+
130+
api-mocker支持代理mock请求到**线上地址**或者**测试地址**,前提是已经在接口设置中配置对应的地址链接,且为绝对路径。
131+
132+
### 开启代理的两种方法
133+
134+
1. 在接口编辑页左侧的 [**代理转发**] 选项勾选对应的转发规则。
135+
2. 可以在请求Mock URL时,带上query参数来设置:
136+
- 转发线上:{ mockURL }?_mockProxyStatus=1
137+
- 转发测试:{ mockURL }?_mockProxyStatus=2
138+
139+
### 代理鉴权
140+
141+
有些接口需要cookie鉴权,而mock地址与线上、测试地址并非同个域名,所以cookie没办法共通。为此api-mocker提供一个配置:mock请求的请求头若设置了字段`api-cookie`,则会使用此字段的值作为代理请求的`cookie`
142+
143+
故开发阶段可以将某个已鉴权cookie,写至mock请求头的`api-cookie`字段,如示例:
144+
```javascript
145+
$.ajax({
146+
url: mockUrl,
147+
method: 'get',
148+
headers: {
149+
'api-coookie': 'your cookie of authentication'
150+
}
151+
})
152+
```
153+
154+
亦或者直接手动将该`cookie`设置到mock请求的域名下,mock服务端会将当前域名的cookie转发到代理请求地址。
155+
156+
> 注:若请求头设置了`api-cookie`,则不会再使用mock请求地址的原本cookie。
157+
128158
## 关于分组
129159

130160
* 系统目前只有一级分组

0 commit comments

Comments
 (0)