Comments (17)
可以用正则解决:
# 以域名 www.test.com 为例
# 把https请求转成http
https://www.test.com http://www.test.com
# 把根路径的请求转发到指定的ip和端口
/^https?:\/\/www\.test\.com(:\d*)?\/?(\?|$)/ 192.168.30.118:8877
# 处理后缀为gif|jpg|jpeg|png|bmp|swf|ico|js|css|html的请求
/^https?:\/\/www\.test\.com(:\d*)?\/\.(gif|jpg|jpeg|png|bmp|swf|ico|js|css|html)(\?|$)/i 127.0.0.1:8080
from whistle.
用rulesFile关联脚本文件或Values里面设置的脚本,利用脚本判断url及请求的headers动态设置规则,如:www.test.com rules:///User/xxx/test.js
from whistle.
看了加入了rulesFile ,文档不是好清晰,能根据上面nginx配置写个Dome吗?
from whistle.
test.js:
url = url.replace(/\?.*$/, '');
if (/^https?:/.test(url)) {
var index = url.indexOf('://') + 3;
url = url.substring(index);
index = url.indexOf('/');
if (index === -1) {
host = url;
url = '/';
} else {
host = url.substring(0, index);
url = url.substring(index);
}
var isRoot = url === '/';
if (isRoot || /\.(gif|jpg|jpeg|png|bmp|swf|ico|js|css|html)$/i.test(url)) {
rules.push(host + ' http://' + host);
rules.push(host + ' ' + (isRoot ? '192.168.30.118:8877' : '127.0.0.1:8080'));
}
}
示例图:
from whistle.
protocol://{test.js}
表示取Values中test.js
的值,protocol:///User/xxx/test.js
表示取本地文件 /User/xxx/test.js
的值
from whistle.
刚测试了,不行,报错
Date: 2017-03-10 08:55:55.676
Error: connect ECONNREFUSED 127.0.0.1:80
at Object.exports._errnoException (util.js:873:11)
at exports._exceptionWithHostPort (util.js:896:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1077:14)
我改下测试可以了,就是配置略复杂,如果能和nginx那样简化配置就好了。
from whistle.
直接修改为这样了
url = url.replace(/?.*$/, '');
if (/^https?:/.test(url)) {
var index = url.indexOf('://') + 3;
url = url.substring(index);
index = url.indexOf('/');
if (index === -1) {
host = url;
url = '/';
} else {
host = url.substring(0, index);
url = url.substring(index);
}
var isRoot = url === '/';
if (isRoot || /.(gif|jpg|jpeg|png|bmp|swf|ico|js|css|html)$/i.test(url)) {
// rules.push(host + ' http://' + host);
// rules.push(host + ' ' + (isRoot ? '192.168.30.118:8877' : '127.0.0.1:8080'));
rules.push(host + ' http://' + '127.0.0.1:8080');
}else{
rules.push(host + ' http://' + '192.168.30.118:8877');
}
}
from whistle.
刚测试了,目前配置直接正则,不起效果
from whistle.
第三条规则改下,用这个
# 以域名 www.test.com 为例
# 把https请求转成http
https://www.test.com http://www.test.com
# 把根路径的请求转发到指定的ip和端口
/^https?:\/\/www\.test\.com(:\d*)?\/?(\?|$)/ 192.168.30.118:8877
# 处理后缀为gif|jpg|jpeg|png|bmp|swf|ico|js|css|html的请求
/^https?:\/\/www\.test\.com(:\d*)?\/[^?]*\.(gif|jpg|jpeg|png|bmp|swf|ico|js|css|html)(\?|$)/i 127.0.0.1:8080
from whistle.
我是这样配置,还是真实地址IP了,不起作用,我访问的是http,不是https直接配置如下:
#Rules
www.test.com rulesFile://{rulesFile.txt}
#rulesFile.txt:
以域名 www.test.com 为例
把https请求转成http
https://www.test.com http://www.test.com
把根路径的请求转发到指定的ip和端口
/^http?://www.test.com(:\d*)?/?(?|$)/ 192.168.30.118:8877
处理后缀为gif|jpg|jpeg|png|bmp|swf|ico|js|css|html的请求
/^http?://www.test.com(:\d*)?/.(gif|jpg|jpeg|png|bmp|swf|ico|js|css|html)(?|$)/i 127.0.0.1:8080
from whistle.
按我最后的这个规则去设置,自己不要乱更改,这个规则同时支持http和https,跟Nginx配置保持一致:
# 以域名 www.test.com 为例
# 把https请求转成http
https://www.test.com http://www.test.com
# 处理后缀为gif|jpg|jpeg|png|bmp|swf|ico|js|css|html的请求
/^https?:\/\/www\.test\.com(:\d*)?\/[^?]*\.(gif|jpg|jpeg|png|bmp|swf|ico|js|css|html)(\?|$)/i 127.0.0.1:8080
# 其它请求
www.test.com 192.168.30.118:8877
from whistle.
测试了,我在w2的网络监控看到了,域名IP无法转发,还是指向源地址,没有效果
from whistle.
加QQ群:462558941
from whistle.
我现在也同样遇到这个问题,使用配置:
/^http://www.subtest.test.com(:\d*)?/[^?]*.(gif|jpg|jpeg|png|bmp|swf|ico|js|css|html)(?|$)/i 192.170.30.12
无法转发到IP地址,还是指向原地址,请问这个问题是怎么解决的?
from whistle.
/^http://www.subtest.test.com(:\d*)?/[^?]*.(gif|jpg|jpeg|png|bmp|swf|ico|js|css|html)(\?|$)/i 192.170.30.12
最后一个问号要转义
from whistle.
我的url是http://subtest.test.com/view/page?query=%E5%88%98%E5%BE%B7%E5%8D%8E&refer=abc
然后我配的规则是:
/^http://www. subtest.test.com(:\d*)?/?(?|$)/ 192.170.30.12
还是没法命中,请问这个配置是否正确呢?
from whistle.
匹配方式很多种,不一定用正则,尽量用合适的方式:https://avwo.github.io/whistle/pattern.html
正则有点问题:(?|$)
-> (\?|$)
下面这种就可以:
192.170.30.12 http://subtest.test.com/view/page
from whistle.
Related Issues (20)
- 有支持br压缩的计划吗 HOT 3
- whistle设置了代理之后手机说无法连接到互联网 HOT 6
- 2.9.70 版本rule(规则)优先级发生变化,在之前版本配置的规则失效 HOT 3
- whistle抓不到支付宝小程序的包 HOT 1
- 使用代理大量请求时Chrome浏览器请求会报错:net::ERR_HTTP2_PROTOCOL_ERROR HOT 7
- No such file or directory HOT 1
- plugin 中如何 使用 values? HOT 3
- /cgi-bin/get-data 的 ids 参数元素过多,导致 URI 地址过长 414 状态码 HOT 5
- ios17.4代理不到8899,换个ios17.3.1就可以 HOT 1
- Error: socket connect timeout HOT 9
- 插件怎么起一个websocket呢,插件UI需要监听返回数据,有没有例子
- 【插件】插件推荐 whistle.devtool
- 请问 resReplace 的 Values中 如果想将”a: 1“ 替换成”a: 2“ 要如何处理 HOT 2
- whistle可以不设置代理,直接作为mock服务器使用吗 HOT 5
- 能否多台电脑的whistle使用同一个HTTPS证书? HOT 3
- whistle不设置代理,直接作为mock服务器调用,可以使用https吗 HOT 2
- log协议提供的界面ui样式不太直观,是否可以优化下样式,或者直接将log原样输出到控制台?
- Mac电脑开启梯子VPN后,代理不生效 HOT 2
- 想删除请求url的某个字段,规则怎么写? HOT 3
- host正则怎么不支持反向引用 HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from whistle.