Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(httpclient): update http_proxy usage #3569

Merged
merged 1 commit into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 deletions docs/source/en/core/httpclient.md
Original file line number Diff line number Diff line change
Expand Up @@ -651,40 +651,37 @@ These are parameters are passed to the [HTTPS] modules,details refer to [`htt

## Debugging Aid

Framework provides [egg-development-proxyagent] plugin to help developers to debug.
If you want to debug the httpclient requests, just need to add below code to `config.local.js`:

Install and enable pulgin:
```js
// config.local.js
module.exports = () => {
const config = {};

```bash
$ npm i egg-development-proxyagent --save
```
// add http_proxy to httpclient
if (process.env.http_proxy) {
config.httpclient = {
request: {
enableProxy: true,
rejectUnauthorized: false,
// proxy: process.env.http_proxy,
},
};
}

```js
// config/plugin.js
exports.proxyagent = {
enable: true,
package: 'egg-development-proxyagent',
return config;
}
```

Open capture tools, we can use [charles] or [fiddler], here we take to [anyproxy] demonstrate

```bash
$ npm install anyproxy -g
$ anyproxy --port 8888
```
then open capture tools(such as [charles] or [fiddler]).

Starting application using environment variables:
after that, just start your application by:

```bash
$ http_proxy=http://127.0.0.1:8888 npm run dev
```

Then it works correctly, and all requests that go through HttpClient can be viewed in the consle of http://localhost:8002.

![anyproxy](https://cloud.githubusercontent.com/assets/227713/21976937/06a63694-dc0f-11e6-98b5-e9e279c4867c.png)

**Note: the pulgin only start in local environments by defalut**
Then it works correctly, and all requests that go through HttpClient can be viewed in the capture tools.

## Known Issues

Expand Down Expand Up @@ -780,7 +777,5 @@ Full examples can be found on [eggjs/examples/httpclient](https://github.com/egg
[formstream]: https://github.com/node-modules/formstream
[HTTP]: https://nodejs.org/api/http.html
[HTTPS]: https://nodejs.org/api/https.html
[egg-development-proxyagent]: https://github.com/eggjs/egg-development-proxyagent
[charles]: https://www.charlesproxy.com/
[fiddler]: http://www.telerik.com/fiddler
[anyproxy]: https://github.com/alibaba/anyproxy
43 changes: 19 additions & 24 deletions docs/source/zh-cn/core/httpclient.md
Original file line number Diff line number Diff line change
Expand Up @@ -662,40 +662,37 @@ console.log(result.res.timing);

## 调试辅助

框架还提供了 [egg-development-proxyagent] 插件来方便开发者调试。
如果你需要对 HttpClient 的请求进行抓包调试,可以添加以下配置到 `config.local.js`:

先安装和开启插件:
```js
// config.local.js
module.exports = () => {
const config = {};

```bash
$ npm i egg-development-proxyagent --save
```
// add http_proxy to httpclient
if (process.env.http_proxy) {
config.httpclient = {
request: {
enableProxy: true,
rejectUnauthorized: false,
// proxy: process.env.http_proxy,
},
};
}

```js
// config/plugin.js
exports.proxyagent = {
enable: true,
package: 'egg-development-proxyagent',
return config;
}
```

开启抓包工具,可以用 [charles] 或 [fiddler],此处我们用 [anyproxy] 来演示下。

```bash
$ npm install anyproxy -g
$ anyproxy --port 8888
```
然后启动你的抓包工具,如 [charles] 或 [fiddler]。

使用环境变量启动应用
最后通过以下指令启动应用

```bash
$ http_proxy=http://127.0.0.1:8888 npm run dev
```

然后就可以正常操作了,所有经过 HttpClient 的请求,都可以在 http://localhost:8002 这个控制台中查看到。

![anyproxy](https://cloud.githubusercontent.com/assets/227713/21976937/06a63694-dc0f-11e6-98b5-e9e279c4867c.png)

**注意:该插件默认只在 local 环境下启动。**
然后就可以正常操作了,所有经过 HttpClient 的请求,都可以你的抓包工具中查看到。

## 常见错误

Expand Down Expand Up @@ -790,7 +787,5 @@ app.httpclient.on('response', result => {
[formstream]: https://github.com/node-modules/formstream
[HTTP]: https://nodejs.org/api/http.html
[HTTPS]: https://nodejs.org/api/https.html
[egg-development-proxyagent]: https://github.com/eggjs/egg-development-proxyagent
[charles]: https://www.charlesproxy.com/
[fiddler]: http://www.telerik.com/fiddler
[anyproxy]: https://github.com/alibaba/anyproxy