前言:习惯了在windows环境中使用Fiddler的童鞋们,是不是感觉它的网络重定向功能很酷,Fiddler能按照你设置的规制捕获网络请求,再指向本地文件,如拦截你的js文件到本地,就能很快的调试线上环境(如后台环境,测试环境,预上线环境等)。但是Fiddler的使用对于初学者来说还是稍有困难的,界面功能很多,导致新手无从下手。(我当初就是这样的),并且Fiddler虽然有Mac版本,但是问题很多,我试了好几次都不行。

正文:今天给大家介绍一款新的神器,nproxy.它能通吃windows,linux.mac平台。而且使用及其简单。一个配置文件就搞定了。

安装:使用npm安装即可

npm install -g nproxy

用法:在replace_rule.js中设置你要重定向的文件路径即可,然后如下执行

nproxy -l replace_rule.js

replace_rule.js示例:

module.exports = [

  // 1. replace single file with local one
{
pattern: 'homepage.js', // Match url you wanna replace
responder: "/home/goddyzhao/workspace/homepage.js"
}, // 2. replace single file with web file
{
pattern: 'homepage.js', // Match url you wanna replace
responder: "http://www.anotherwebsite.com/assets/js/homepage2.js"
}, // 3. replace combo file with src with absolute file path
{
pattern: 'group/homepageTileFramework.*.js',
responder: [
'/home/goddyzhao/workspace/webapp/ui/homepage/js/a.js',
'/home/goddyzhao/workspace/webapp/ui/homepage/js/b.js',
'/home/goddyzhao/workspace/webapp/ui/homepage/js/c.js'
]
}, // 4. replace combo file with src with relative file path and specified dir
{
pattern: 'group/homepageTileFramework.*.js',
responder: {
dir: '/home/goddyzhao/workspace/webapp/ui/homepage/js',
src: [
'a.js',
'b.js',
'c.js'
]
}
}, // 5. Map server image directory to local image directory
{
pattern: 'ui/homepage/img', // must be a string
responder: '/home/goddyzhao/image/' //must be a absolute directory path
}, // 6. Write responder with regular expression variables like $1, $2
{
pattern: /https?:\/\/[\w\.]*(?::\d+)?\/ui\/(.*)_dev\.(\w+)/,
responder: 'http://localhost/proxy/$1.$2'
}, // 7. Map server image directory to local image directory with regular expression
// This simple rule can replace multiple directories to corresponding locale ones
// For Example,
// http://host:port/ui/a/img/... => /home/a/image/...
// http://host:port/ui/b/img/... => /home/b/image/...
// http://host:port/ui/c/img/... => /home/c/image/...
// ...
{
pattern: /ui\/(.*)\/img\//,
responder: '/home/$1/image/'
}
];

  nproxy参数说明:

Options:

  -h, --help         output usage information
-V, --version output the version number
-l, --list [list] Specify the replace rule file
-p, --port [port] Specify the port nproxy will listen on(8989 by default)
-t, --timeout [timeout] Specify the request timeout (5 seconds by default)

改变默认监听端口:因为要捕获网络请求,nproxy必然会监听请求地址和请求端口,它默认的监听端口为8989,你可以通过-p参数来设置,如

nproxy -l replace_rule.js  -p 8181

  即可改变监听的端口。

浏览器代理设置:代理地址为127.0.0.1 端口即为你要监听的端口,如8181.至于怎么设置浏览器的代理,请百度就知道了。

通过以上步骤,你就搭建起了前端调试环境。可以方便的直接调用后端的接口,而不用在本地造一大堆假数据了。是不是很方便了?

现在就来试试吧!

  

最新文章

  1. Kosaraju 算法检测有向图的强连通性
  2. 安装nfs服务器
  3. js post提交页面
  4. ECSHOP在线手册布局参考图--文章详情页 article.dwt
  5. UITableViewCell 高度自适应
  6. 你以为PHP那么好自定义升级?
  7. BeanUtils属性
  8. [笔记]ACM笔记 - 利用FFT求卷积(求多项式乘法)
  9. Redis和Memcached区别
  10. Node.js C/C++ 插件
  11. 【shell基础】数学计算
  12. ArcGIS自定义工具箱-字段分割
  13. loadrunner 运行场景-命令行运行场景
  14. 1.9 Android程序签名打包
  15. Nginx入门【转】
  16. VS2008生成数据库连接字串
  17. HTTPS实战之单向验证和双向验证
  18. PHP + Apache 在 Linux(centos7)系统下的环境搭建,基于 yum
  19. git命令(持续更新)
  20. python所有基础

热门文章

  1. 如何定位BAD_ACCESS
  2. SPU - SKU - ARPU
  3. MySQL存储引擎(engine:处理表的处理器)
  4. Spring 学习笔记(一)
  5. php序号发生器,数字重组,可以隐藏原来的1,2,3。。。
  6. 每天一个linux命令(性能、优化):【转载】vmstat命令
  7. 《DSP using MATLAB》示例Example 6.12
  8. Django基于Form之登录和注册
  9. ballerina 学习十六 错误&&异常处理
  10. C语言控制台窗体图形界面编程(八):鼠标事件