百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术教程 > 正文

前端开发调试最佳工具——Whistlejs

suiw9 2024-11-16 00:31 22 浏览 0 评论

相信很多前端的小伙伴在调试接口的时候都碰到这么一个问题、比如移动端h5的软键盘弹起、微信公众号的分享、导航、支付之类的功能、是没有办法在本地调试的。你可能会说可以用内网穿透、微信开发者工具等等工具。没错,这也是一种处理方式,但是相对于需要域名的业务、或者说生产上的bug你在本地无法复现,这个时候你怎么办呢?

废话不多说,今天就由我这个前端练习生来给大家推荐一个工具——whistlejs,真的是非常强大的一款工具,关键是不收米(白嫖是我们码农的优良产统)。

whistlejs基于Node实现的跨平台web调试代理工具,类似的工具有Windows平台上的Fiddler,主要用于查看、修改HTTP、HTTPS、Websocket的请求、响应,也可以作为HTTP代理服务器使用,不同于Fiddler通过断点修改请求响应的方式,whistle采用的是类似配置系统hosts的方式,一切操作都可以通过配置实现,支持域名、路径、正则表达式、通配符、通配路径等多种匹配方式,且可以通过Node模块扩展功能。

安装启动

Mac 或 Windows 系统可以采用一键安装:https://juejin.cn/post/7096345607740063775

whistle安装过程需要以下步骤(缺一不可):

  1. 安装Node
  2. 安装whistle
  3. 启动whistle
  4. 配置代理
  5. 安装根证书

1. 安装Node

whistle支持v0.10.0以上版本的Node,为获取更好的性能,推荐安装最新版本的Node。

如果你的系统已经安装了v0.10.0以上版本的Node,可以忽略此步骤,直接进入安装whistle的步骤,否则:

  1. Windows或Mac系统,访问https://nodejs.org/,安装LTS版本的Node,默认安装即可。
  2. Linux下推荐使用源码安装: 从Node官网下载最新版的Source Code(或者用wget命令下载),解压文件(tar -xzvf node-vx.y.z.tar.gz)后进入解压后的根目录(node-vx.y.z),依次执行./configure./make./make install

安装完Node后,执行下面命令,查看当前Node版本

$ node -v
v4.4.0

如果能正常输出Node的版本号,表示Node已安装成功(Windows系统可能需要重新打开cmd)。

2. 安装whistle

Node安装成功后,执行如下npm命令安装whistle (Mac或Linux的非root用户需要在命令行前面加sudo,如:sudo npm install -g whistle

$ npm install -g whistle

npm默认镜像是在国外,有时候安装速度很慢或者出现安装不了的情况,如果无法安装或者安装很慢,可以使用taobao的镜像安装:

$ npm install cnpm -g --registry=https://registry.npmmirror.com
$ cnpm install -g whistle

或者直接指定镜像安装:
$ npm install whistle -g --registry=https://registry.npmmirror.com

whistle安装完成后,执行命令 whistle helpw2 help,查看whistle的帮助信息

$ w2 help

  Usage: whistle <command> [options]

  Commands:

  status              Show the running status of whistle
  use/add [filepath]  Set rules from a specified js file (.whistle.js by default)
  run                 Start a front service
  start               Start a background service
  stop                Stop current background service
  restart             Restart current background service
  help                Display help information

  Options:

  -h, --help                                      output usage information
  -D, --baseDir [baseDir]                         set the configured storage root path
  -z, --certDir [directory]                       set custom certificate store directory
  -l, --localUIHost [hostname]                    set the domain for the web ui of whistle (local.whistlejs.com by default)
  -L, --pluginHost [hostname]                     set the domain for the web ui of plugin  (as: "script=a.b.com&vase=x.y.com")
  -n, --username [username]                       set the username to access the web ui of whistle
  -w, --password [password]                       set the password to access the web ui of whistle
  -N, --guestName [username]                      set the the guest name to access the web ui of whistle (can only view the data)
  -W, --guestPassword [password]                  set the guest password to access the web ui of whistle (can only view the data)
  -s, --sockets [number]                          set the max number of cached long connection on each domain (60 by default)
  -S, --storage [newStorageDir]                   set the configured storage directory
  -C, --copy [storageDir]                         copy the configuration of the specified directory to a new directory
  -c, --dnsCache [time]                           set the cache time of DNS (30000ms by default)
  -H, --host [boundHost]                          set the bound host of whistle (INADDR_ANY by default)
  -p, --port [proxyPort]                          set the proxy port of whistle (8899 by default)
  -P, --uiport [uiport]                           set the listening port of whistle webui
  -m, --middlewares [script path or module name]  set the express middlewares loaded at startup (as: xx,yy/zz.js)
  -M, --mode [mode]                               set the way of starting the whistle mode (as: pureProxy|debug|multiEnv)
  -t, --timeout [ms]                              set the request timeout (66000ms by default)
  -e, --extra [extraData]                         set the extra parameters for plugin
  -f, --secureFilter [secureFilter]               set the path of secure filter
  -R, --reqCacheSize [reqCacheSize]               set the cache size of request data (600 by default)
  -F, --frameCacheSize [frameCacheSize]           set the cache size of webSocket and socket's frames (512 by default)
  -A, --addon [pluginPaths]                       add custom plugin paths
  --httpPort [httpPort]                           set the http server port of whistle
  --httpsPort [httpsPort]                         set the https server port of whistle
  --no-global-plugins                             do not load any globally installed plugins
  --no-prev-options                               do not reuse the previous options when restarting
  -V, --version                                   output the version number

如果能正常输出whistle的帮助信息,表示whistle已安装成功。

有关命令行参数参见:命令行参数

3. 启动whistle

最新版本的whistle支持三种等价的命令whistlew2wproxy

启动whistle:

$ w2 start

Note: 如果要防止其他人访问配置页面,可以在启动时加上登录用户名和密码 -n yourusername -w yourpassword

重启whsitle:

$ w2 restart

停止whistle:

$ w2 stop

调试模式启动whistle(主要用于查看whistle的异常及插件开发):

$ w2 run

启动完whistle后,最后一步需要配置代理。

4. 配置代理

配置信息

  1. 代理服务器:127.0.0.1 (如果部署在远程服务器或虚拟机上,改成对应服务器或虚拟机的ip即可)
  2. 默认端口:8899 (如果端口被占用,可以在启动时通过 -p 来指定新的端口,更多信息可以通过执行命令行 w2 help (v0.7.0及以上版本也可以使用w2 help) 查看)

勾选上 对所有协议均使用相同的代理服务器

代理配置方式(把上面配置信息配置上即可)

  1. 全局代理 (推荐),可通过命令行设置参考设置代理,也可以手动配置:
  • Windows
  • Mac: System Preferences > Network > Advanced > Proxies > HTTP or HTTPS


  • Linux: Settings > Network > VPN > Network Proxy > Manual
  1. 浏览器代理 (推荐):安装浏览器代理插件
  • 安装Chrome代理插件:推荐安装SwitchyOmega
  • Firefox: 地址栏输入访问 about:preferences,找到 Network Proxy,选择 手动代理配置(Manual proxy configuration),输入代理服务器地址、端口,保存


  1. 移动端需要在设置中配置当前Wi-Fi的代理,以 iOS 为例:

PS: 如果配置完代理,手机无法访问,可能是whistle所在的电脑防火墙限制了远程访问whistle的端口,关闭防火墙或者设置白名单:http://jingyan.baidu.com/article/870c6fc317cae7b03ee4be48.html

访问配置页面

启动whistle及配置完代理后,用Chrome浏览器(由于css兼容性问题界面只支持Chrome浏览器)访问配置页面,如果能正常打开页面,whistle安装启动完毕,可以开始使用。

可以通过以下两种方式来访问配置页面:

  • 方式1:域名访问 http://local.whistlejs.com/
  • 方式2:通过ip+端口来访问,形式如 http://whistleServerIP:whistlePort/ e.g. http://127.0.0.1:8899
  • 方式2:通过命令行参数 -P xxxx 自定义webui的端口(xxxx表示要设置的端口号),自定义端口支持上述两种方式访问,也支持 http://127.0.0.1:xxxx

5. 安装根证书

安装证书请参考文档: http://wproxy.org/whistle/webui/https.html

相关推荐

看完这一篇数据仓库干货,终于搞懂什么是hive了

一、Hive定义Hive最早来源于FaceBook,因为FaceBook网站每天产生海量的结构化日志数据,为了对这些数据进行管理,并且因为机器学习的需求,产生了Hive这们技术,并继续发展成为一个成...

真正让你明白Hive参数调优系列1:控制map个数与性能调优参数

本系列几章系统地介绍了开发中Hive常见的用户配置属性(有时称为参数,变量或选项),并说明了哪些版本引入了哪些属性,常见有哪些属性的使用,哪些属性可以进行Hive调优,以及如何使用的问题。以及日常Hi...

HIVE SQL基础语法(hive sql是什么)

引言与关系型数据库的SQL略有不同,但支持了绝大多数的语句如DDL、DML以及常见的聚合函数、连接查询、条件查询。HIVE不适合用于联机事务处理,也不提供实时查询功能。它最适合应用在基于大量不可变数据...

[干货]Hive与Spark sql整合并测试效率

在目前的大数据架构中hive是用来做离线数据分析的,而在Spark1.4版本中spark加入了sparksql,我们知道spark的优势是速度快,那么到底sparksql会比hive...

Hive 常用的函数(hive 数学函数)

一、Hive函数概述及分类标准概述Hive内建了不少函数,用于满足用户不同使用需求,提高SQL编写效率:...

数仓/数开面试题真题总结(二)(数仓面试时应该讲些什么)

二.Hive...

Tomcat处理HTTP请求流程解析(tomcat 处理请求过程)

1、一个简单的HTTP服务器在Web应用中,浏览器请求一个URL,服务器就把生成的HTML网页发送给浏览器,而浏览器和服务器之间的传输协议是HTTP,那么接下来我们看下如何用Java来实现一个简单...

Python 高级编程之网络编程 Socket(六)

一、概述Python网络编程是指使用Python语言编写的网络应用程序。这种编程涉及到网络通信、套接字编程、协议解析等多种方面的知识。...

[904]ScalersTalk成长会Python小组第20周学习笔记

Scalers点评:在2015年,ScalersTalk成长会Python小组完成了《Python核心编程》第1轮的学习。到2016年,我们开始第二轮的学习,并且将重点放在章节的习题上。Python小...

「web开发」几款http请求测试工具

curl命令CURL(CommandLineUniformResourceLocator),是一个利用URL语法,在命令行终端下使用的网络请求工具,支持HTTP、HTTPS、FTP等协议...

x-cmd pkg | hurl - 强力的 HTTP 请求测试工具,让 API 测试更加简洁高效

简介...

Mac 基于HTTP方式访问下载共享文件,配置共享服务器

方法一:使用Python的SimpleHTTPServer进行局域网文件共享Mac自带Python,所以不需要安装其他软件,一条命令即可...

Python 基础教程十五之 Python 使用requests库发送http请求

前言...

使用curl进行http高并发访问(php curl 大量并发获得结果)

本文主要介绍curl异步接口的使用方式,以及获取高性能的一些思路和实践。同时假设读者已经熟悉并且使用过同步接口。1.curl接口基本介绍curl一共有三种接口:EasyInterface...

Django 中的 HttpResponse理解和用法-基础篇1

思路是方向,代码是时间,知识需积累,经验需摸索。希望对大家有用,有错误还望指出。...

取消回复欢迎 发表评论: