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)
- 请问whistle作为独立npm如何使用 HOT 1
- "Accept-Encoding" 丢失参数 HOT 3
- 什么时候可以支持http/3呢? HOT 1
- socket connect timeout HOT 4
- rule生效问题 HOT 3
- 无法代理vscode本地debug服务 HOT 2
- 方向代理是否支持其他协议 HOT 1
- 使用@链接到本地文件的规则扩展是否可以及时更新 HOT 4
- 这种情况怎么配置, 两个前端服务访问同一个域名, 不同端口 HOT 4
- X-Forwarded-For Header 浏览器插件,配置`x-forwarded-for`字段无效 HOT 2
- 全栈开发 Whistle 影响Java Gradle HOT 3
- xxx.com.cn 网址代理不成功 HOT 1
- mac、node18以上版本不兼容,代理出现状态码502 HOT 15
- Custom Rules! HOT 1
- post 请求,使用 reqAppend 怎么在 formdata 里增加参数?貌似现在只能把字符串增加到body后面 HOT 1
- mac安装证书后,设置全局代理,提示网络错误 HOT 1
- 本地开发启用 HTTP2,开 whistle host 之后请求变得很慢 HOT 5
- resCors://*对部分请求无效? HOT 2
- whistle's time is diff from chrome devtool's time HOT 2
- 能否设置一个全局变量代表当前的ip地址啊 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.