From 8de804d36b78c18adfb11b9ac53d33850fca731f Mon Sep 17 00:00:00 2001 From: TZ Date: Tue, 26 Mar 2019 11:55:43 +0800 Subject: [PATCH] docs(httpclient): update http_proxy usage --- docs/source/en/core/httpclient.md | 43 ++++++++++++---------------- docs/source/zh-cn/core/httpclient.md | 43 ++++++++++++---------------- 2 files changed, 38 insertions(+), 48 deletions(-) diff --git a/docs/source/en/core/httpclient.md b/docs/source/en/core/httpclient.md index 1e870089ba..3d47f58ad2 100644 --- a/docs/source/en/core/httpclient.md +++ b/docs/source/en/core/httpclient.md @@ -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 @@ -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 diff --git a/docs/source/zh-cn/core/httpclient.md b/docs/source/zh-cn/core/httpclient.md index 3a4b9fe67d..e5be99d8e4 100644 --- a/docs/source/zh-cn/core/httpclient.md +++ b/docs/source/zh-cn/core/httpclient.md @@ -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 的请求,都可以你的抓包工具中查看到。 ## 常见错误 @@ -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