Skip to content

Commit fe807f2

Browse files
author
xcodebuild
committed
Squashed 'vendor/whistle/' changes from bd55e0d56..826e040c9
826e040c9 style: shitf + copy to edit the copied text be49c171d test: refine code 5a21a1a61 Release v2.7.7 50b731574 refactor: export wsParser to plugin 497f619da fix: pipe://plugin cannot handle binary frame issues 11c8bd736 style: refine disabled status color f409be09a style: show custom root ca cb6b2350a refactor: auto resume stream 84ca52ca7 style: hint pipe list 2bc4fd407 style: Copy path -> Delete b45467fb6 Release v2.7.6 6c7bf4967 refactor: allow to enable rejectUnauthorized 3b50f323a style: show dns over https in UI 249fc21a6 style: refine error tips a39771a8c Release v2.7.6 842f5674e refactor: refine error message 1551b2265 refactor: ignore uncaughtException 707105da8 feat: custom dnsOverHttps 1fc02de43 fix: delete headers[config.PROXY_ID_HEADER] c4cf5f716 refactor: refine code 8c65602eb refactor: set max vars length = 30 501177eaa chore: update package-lock.json 59243f3e3 docs: update image 84bb7b811 refactor: enlarge max length of plugin vars e34683610 refactor: refine code e2f417d69 style: allow custom hints by plugin 5ddd552e4 feat: need to manually open pluginVars 0c5cd49f6 refactor: refine code 0437661ba refactor: refine code 5180032fa feat: whistle.xxx.var$ === whistle.xxx.var[lastIndex] d14d7acb6 style: refine help url 832442478 Release v2.7.5 f042af5e7 feat: add tpl var whistle.xxx.var 83f8731dd style: show plugin vars hints 51edb0078 feat: pipe plugin vars fc624e0bb refactor: refine code ec0dac3b8 feat: send pluginVars to plugin server 02c3a78ce refactor: refine code 6d97de3cf feat: add plugin vars f6d9cb1e7 Release v2.7.5 dfe6758fd feat: add disable://interceptConsole 0d9baf8b7 refactor: refine request time of http2 5c4c85f61 refactor: refine code 02af148de feat: allow to change protocol 8036e6125 docs: 修改mac下载路径 128c308ef refactor: refine code d7257bdb4 feat: filter requests by url f46e6624e style: refine filter 234bcafb4 Release v2.7.4 2cf4821b0 style: refine ui cf1b8c91e style: refine certs dialog 8633edf29 chore: ignore CHANGELOG.md bb8c7996e refactor: refine delete://xxx 35c5adae7 refactor: refine code 2e89aee99 refactor: refine code 2c4a813ec refactor: refine shadowRules 41037b1b3 style: refine plugins mode 57bff2d4b style: refine context menu 6dd63b94b Release v2.7.3 f20c3f934 feat: add shadowRules Mode d6abfe350 feat: setShadowRules 9c8d466c5 style: Recover -> Restore 3500f0c53 style: refine wording 1e4411006 style: let go of the restrictions on replay 360d22750 Release v2.7.3 1e7cc4060 style: add context menu of left menu bar 7536f4384 fix: Copy Key 1d84ed5df style: fix wording dbe765b29 style: refine ui 421897d84 style: use icon instead of wording 0db0d84cd test: 500 -> 404 5303f1890 style: refine ui 8bb2aa7ba style: show recoding state a2d3c8d5f refactor: refine code d2247afbb feat: add WHISTLE_ROOT 77dae6bba style: refine wording 28d63d867 style: refine ui d0dff1c09 style: refine record button 497e2c450 style: refine record button 8fda19af9 refactor: refine dns 3570c7009 Release v2.7.2 46c9fb2e8 style: refine ui af527a859 refactor: refine code d63693443 style: refine ui f5047eb5b Release v2.7.2 3cdc7bf4d feat: add optional options f11c2c117 Release v2.7.2 ecf4b30d6 style: show custom DNS servers adf108230 feat: custom DNS server 6fe656d18 refactor: refine code 099dc34dd feat: allow custom dns servers b09ad9cd8 style: Recyle Bin -> Trash 1e9f19ca4 style: refine code c628a845b style: fix sort by columns 2c8617657 style: hide scrollbar 752358944 refactor: remove part of the configuration passed to the plugin 44f2fe912 style: refine ui 8bff3ed0b style: refine code 6eb82646e style: refine network list 88c816c31 Release v2.7.1 87407e1a0 style: auto refresh tree view 2c576068b style: refine code 386cff137 style: refine code 9234e9b7f refactor: fix audit d25ec4b95 style: refine ui 3e9947868 fix: avwo/whistle#573 638aa34c4 feat: allow to custom client id key 4e08e3202 feat: allow to custom client id key 19d6d5df0 feat: allow to custom client ip field 01dd71703 feat: allow to custom x-whistle-tunnel-data 3f9bc52d1 style: show Client ID eaa709f0e style: switch view by context menu c5bc1a96b style: refine ui ab14c8496 style: refine filter d7076252b refactor: refine code b52fcba02 Release v2.7.0 0b36fd570 style: show raw url 7a31edbbf feat: show forwarded url 89a06e7f1 refactor: refine code 19927562c style: highlight new requests 4c92901fa style: add off highlight option 8c94eae95 style: remove tree node 456473a26 style: highlight new requests ce123358c Release v2.7.0 049bd94df fix: shift + select bd7b7a31f style: refine replay 5ff6bf2a8 style: refine code aabc29e79 style: refine replay 353ed1e14 style: ensure scroll to view when replay request 3f0840961 style: refine code 550cfb55c refactor: refine code 997931f1d feat: pac://user:pass@url bca017341 style: only switch the view under Network 7e03d12c0 style: show error code 52c51b617 style: fix checkHide 4946dd937 style: refine ui 9976bf633 refactor: reqScript.getValue(key, onlyValues) b74b64ef6 style: refine copy button 38e6193ec style: filter tree f61bff9f1 style: refine expand & collapse tree 32b5e2163 perf: refine code ea940f0ec style: double click to show inspectors by default 12c401d45 style: handle tree view 82cb4b01c style: init tree view 9c57dc8d7 refactor: refine code e98ef4245 style: refine tree view ea8cce9a7 refactor: update tree 20df9d28e style: filter tree 7fe47c1af refactor: refine code 61d8356c6 feat: build a tree structure ab7cf30ea feat: build a tree structure 0626539eb refactor: refine code 1d1fde6b3 style: close autoRefresh 033ad1b15 style: refine ui e56e8284c style: refine context menu e3006291f style: type icon b02607033 feat: allow to switch view by query string 481143c98 style: refine copy menu a833613bf style: bold the request that matches the rules 87664e73f style: fix context menu status c5f6d3edf style: refine ui 32773ee4b style: add access key Ctrl[Command] + B a618db016 fix: auto update structure view c49d066cc style: handle the structure view of tunnel requests 124d57841 style: refine code f79f3d9c9 style: export sessions by path 6a2137bdf style: refine tunnel url fd8bce5c6 style: refine code 7c40a8b72 style: refine code a5e7d9bee style: doubleclick to show Inspectors 37e0e87f7 style: add scroller d5cbc6ead style: prevent dbclick a93985034 style: refine switch to structure view button ea0b61345 style: refine switch button 1aa613a2d refactor: set title 3518060e6 style: refine ui 853ba6467 style: click lable to toggle the tree node ff4ef68aa style: remove console.log 266b8eb42 style: refine border a964db2fa refactor: remove comma-dangle dbb7f156f style: change font size 14 -> 12 6b53f4980 update package-lock.json 5c4d5b2bc feat(network): add tree view in network panel 0ad8e9e5f refactor: refine code e15bc30d5 feat: eanble://keepClientId 10fa9c12d feat: add tpl var clientId f2f8e21b9 feat: eanble://keepClientId 5f65b40cd refactor: refine filename 524e3363d refactor: refine checkClientIp 993bb907c fix: the filename too long and cannot be saved eec3df8ca Release v2.6.16 aa9c36ae5 refactor: reload data 078b1817e refactor: refine code cb54c4f5f refactor: allow to custom whistle internal path e6377c459 refactor: use /.whistle-path.5b6af7b9884e1165/ instead of /...whistle-path.5b6af7b9884e1165.../// a1c2b00da refactor: refine code 8a636dbc7 refactor: refine wildcard pattern 32c7d7275 refactor: refine code f785cad32 feat: enable rules by double click line number 1289f5342 refactor: refine code eae57d3a7 Release v2.6.15 305a13c6a style: dblclick to enable&disable rules 95dae503f refactor: refine code d15d01044 feat: allow custom whistle editor 9288e9331 refactor: refine shadowRules e6459f2e5 style: add title d4a6a51d6 style: add ObjectToQuery 75086481e refactor: refine code cbc1c4274 refactor: refine cli tips 1cab7a2cf refactor: w2 add f3ee3dd05 refactor: refine getHostPort d2560ceb3 refactor: refine code 0d7134899 Release v2.6.14 db91d34e9 refactor: update node-pac 7ecad2431 ci: add node16 272b952ac chore: hide warnings 6346927b3 refactor: abort -> destroy 9e69b78bb Release v2.6.13 b4026dc59 refactor: refine code 66d1fc9d5 refactor: refine code b89e2bf11 refactor: refine filter 77e3b8206 refactor: set server.timeout = config.timeout 4171ab061 Release v2.6.13 a9cb6da67 style: avwo/whistle#557 88c773e09 style: refine code b943a9fa0 style: add context menu: Open/Source 8e6e4747c refactor: add timeout event 9454a8201 Release v2.6.12 41d15d09f Release v2.6.12 9d8ba0c6b feat: disable://proxyConnection to set Proxy-Connection: close bde9dbdcd Release v2.6.12 f56976a8e feat: filter by clientId ea97989d0 style: set min-width = 1100px 655aea1da perf: close closed request 3d5c9c31b refactor: refine code 37f7d0403 style: add qps title 4142de1af Release v2.6.11 8783b8b94 style: show max cpu & mem & qps 568aa99d8 style: show QPS 5c80fcded refactor: auto destroy proxy connection 856b0d4f9 refactor: handle http.request errors 1e8952c64 refactor: refine code 5e02705ee refactor: fix ERR_HTTP_TRAILER_INVALID e381dd77b refactor: refine code c5960854d feat: resolveInternalHost 8ac6e1187 refactor: refine code 6ce4766a2 Release v2.6.10 1f218daab refactor: refine code 6ac5328b4 refactor: export har e58f0b254 refactor: filter plugin names that contain underscore b27e4520e refactor: change recycle bin size: 120 -> 200 1f06580f6 refactor: add x-whistle-transit-version 612c7459a refactor: refine code a8d754dc2 docs: plugins 0492aae5c refactor: refine code 6c2ad183f refactor: custom ui host by _whistleInternalHost_ param of url c24fbba22 refactor: refine proxy domain name 9f32cfca6 style: refine postData a4f091c36 style: fix content size 3ee359df4 style: export har with client port a63084919 style: parse cookies for har f79ab77df feat: -M 'disabledBackOption|disabledMultipleOption|notAllowDisableRules' 06cac7a46 feat: handle har data c2dd772f5 style: whistle to har cb18a30a6 feat: add export har option 771e28744 refactor: refine code 00661c980 rafactor: import har file 2bc413803 style: refine code e202e3cba feat: allow to change editor state by hash change 3c79e26f9 style: show total count of list fd4d65b05 refactor: update devDeps b76924afd refactor: audit fix 95cfa1a99 Release v2.6.9 aae7bb066 style: allow to disabledEditor=1 by whistle.location.search 4e0078652 feat: allow to add Rules&Values by --shadowRules 05fa22112 refactor: no login required to get the list of installed plugins d7266dcf6 style: fix word spelling errors e52e2a002 refactor: refine shadowRules 120d886f9 Release v2.6.8 a4a7e1dd8 fix: filters e1c69c334 refactor: initial === initialize bb866cf40 refactor: refine code 2c6f362a3 style: set min-width 7c4c185d8 refactor: add updateTime f4cce8c50 refactor: hide baseDir in network or plugins mode 8a90f2386 style: show pluginsOnly & rulesOnly mode dfe6c51e4 feat: add pluginsOnly|rulesOnly mode git-subtree-dir: vendor/whistle git-subtree-split: 826e040c92e5ba94d20c29751b08b8c8f6251f74
1 parent 367fce1 commit fe807f2

File tree

114 files changed

+5353
-2747
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+5353
-2747
lines changed

.babelrc

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
{
2-
"presets": [
3-
"react"
4-
],
5-
"ignore": [
6-
"./biz/webui/htdocs/src/js/components/json/eval.js"
7-
]
8-
}
2+
"presets": [
3+
"env",
4+
"react"
5+
],
6+
"plugins": [
7+
"transform-class-properties",
8+
"transform-object-rest-spread"
9+
],
10+
"ignore": [
11+
"./biz/webui/htdocs/src/js/components/json/eval.js"
12+
]
13+
}

.eslintrc

Lines changed: 51 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,55 @@
11
{
2-
"env": {
3-
"browser": true,
4-
"node": true
5-
},
6-
"extends": [
7-
"eslint:recommended",
8-
"plugin:react/recommended"
2+
"env": {
3+
"browser": true,
4+
"node": true,
5+
"es6": true
6+
},
7+
"extends": [
8+
"eslint:recommended",
9+
"plugin:react/recommended"
10+
],
11+
"parser": "babel-eslint",
12+
"parserOptions": {
13+
"ecmaFeatures": {
14+
"experimentalObjectRestSpread": true,
15+
"jsx": true
16+
}
17+
},
18+
"plugins": [
19+
"react"
20+
],
21+
"rules": {
22+
"indent": [
23+
"error",
24+
2
925
],
10-
"parser": "babel-eslint",
11-
"parserOptions": {
12-
"ecmaFeatures": {
13-
"experimentalObjectRestSpread": true,
14-
"jsx": true
15-
}
16-
},
17-
"plugins": [
18-
"react"
26+
"react/prop-types": 0,
27+
"react/no-direct-mutation-state": 0,
28+
"linebreak-style": [
29+
"error",
30+
"unix"
1931
],
20-
"rules": {
21-
"indent": [
22-
"error",
23-
2
24-
],
25-
"react/prop-types": 0,
26-
"react/no-direct-mutation-state": 0,
27-
"linebreak-style": [
28-
"error",
29-
"unix"
30-
],
31-
"quotes": [
32-
"error",
33-
"single"
34-
],
35-
"semi": [
36-
"error",
37-
"always"
38-
],
39-
"no-unused-vars": [
40-
"error",
41-
{
42-
"vars": "all",
43-
"args": "none"
44-
}
45-
],
46-
"no-empty": [
47-
"error",
48-
{ "allowEmptyCatch": true }
49-
],
50-
"no-cond-assign": "off"
51-
}
32+
"quotes": [
33+
"error",
34+
"single"
35+
],
36+
"semi": [
37+
"error",
38+
"always"
39+
],
40+
"no-unused-vars": [
41+
"error",
42+
{
43+
"vars": "all",
44+
"args": "none"
45+
}
46+
],
47+
"no-empty": [
48+
"error",
49+
{
50+
"allowEmptyCatch": true
51+
}
52+
],
53+
"no-cond-assign": "off"
54+
}
5255
}

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ assets/launcher
6262
/biz/webui/htdocs/src
6363
/docs
6464
/.history
65+
CHANGELOG.md
6566

6667

6768
# Coveralls

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ node_js:
66
- "13"
77
- "14"
88
- "15"
9+
- "16"
910

1011
install:
1112
- npm install

CHANGELOG.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,79 @@
1+
# v2.7.7
2+
1. fix: [pipe](https://wproxy.org/whistle/rules/pipe.html) 无法直接透传 WebSocket 的二进制包问题
3+
2. style: 支持显示自定义根证书及删除自定义证书导引
4+
3. style: `pipe` 支持智能提示
5+
6+
# v2.7.6
7+
1. feat: 支持通过类似 `--dnsServer http://dns.alidns.com/resolve` 自定义 `dns-over-https` 服务: https://github.com/avwo/whistle/issues/439
8+
2. style: 优化错误提示
9+
10+
# v2.7.5
11+
1. feat: 支持通过 `disable://interceptConsole` 禁止 `log://` 拦截 `console` 的请求,用户只能通过代码 `window._whistleConsole && _whistleConsole.xxx(a, b, ...)` 记录日志
12+
2. feat: 支持在规则里面同时设置多个s `%plugin-name=xxxx` (最多 10 个),Whistle 会自带将这些值带到插件的对象: `req.originalReq.pluginVars`
13+
3. refactor: 显示插件转发的 HTTP 协议
14+
15+
# v2.7.4
16+
1. refactor: 调整 `delete://reqH.xxxx` 的时机
17+
18+
# v2.7.3
19+
1. style: 优化左侧菜单
20+
2. styl: 修复 Values 右键菜单 Copy / Key 弹出创建新 key 输入框问题
21+
3. feat: 支持设置 `-M shadowRules` (抓包 + 设置 shadowRules) 或 `-M shadowRulesOnly` (无法查看抓包)
22+
23+
# v2.7.2
24+
1. feat: 支持通过命令行参数 `--dnsServer "1.1.1.1,8.8.8.8,10.3.2.1:8080"` 自定义 DNS server
25+
> 如果需要请求自定义 DNS server 出错时自动转成默认可以用: `--dnsServer "1.1.1.1,8.8.8.8,10.3.2.1:8080,default"`
26+
> 自定义 DNS server,默认是获取 IPv4,如果需要获取 IPv6,要手动指定 `--dnsServer "2001:4860:4860::8888,[2001:4860:4860::8888]:1053,ipv6"`
27+
2. fix: 修复 List View 通过表头排序后无法 Reset 的问题
28+
29+
# 2.7.1
30+
1. fix: Tree View 抓包数据满了后无法自动更新问题
31+
# v2.7.0
32+
1. feat: Network 支持 Tree View 展示
33+
2. feat: `pac` 支持设置用户名密码:`pac://user:pass@pacPath`
34+
3. style: 支持显示 `Raw Url` 详见:https://github.com/avwo/whistle/issues/572
35+
36+
# v2.6.16
37+
1. fix: 解决规则文件名称过长保存失败的问题
38+
2. feat: 域名统配也支持获取子匹配内容
39+
40+
# v2.6.15
41+
1. refactor: 优化命令行启动输出的信息
42+
2. feat: 编辑器 `Show Line Number` 时,双击行数可以注释或取消注释
43+
3. feat: `Network / Tools / Toolbox` 支持将对象转成 `Query` 参数
44+
4. style: 支持扩展 `util.openEditor(value)` 方法
45+
46+
# v2.6.14
47+
1. chore: https://github.com/avwo/whistle/issues/559
48+
49+
# v2.6.13
50+
1. style: Network 搜索框支持最多3个关键字过滤
51+
2. style: Network 右键菜单新增 `Open/Source` 查看当前抓包数据的源码
52+
3. refactor: `onSocketEnd` 添加 `timeout` 事件,兼容各种诡异行为
53+
4. refactor: 优化内部连接管理
54+
55+
# v2.6.12
56+
1. feat: 支持通过 url 参数的 clientId 过来抓包数据
57+
2. feat: 支持通过 `disable://proxyConnection` 将代理转发头改为 `Proxy-Connection: close`
58+
59+
# v2.6.11
60+
1. perf: 确保及时关闭无用连接,减少内存占用
61+
2. style: Online 支持显示 QPS,及 内存、CPU、QPS 的最大值
62+
3. refactor: 处理处理请求过程中无法捕获的异常
63+
64+
# v2.6.10
65+
1. feat: 支持导出 har 文件
66+
2. feat: 支持设置 `-M "disabledBackOption|disabledMultipleOption|notAllowDisableRules"`
67+
3. feat: 内部路径 `/...whistle-path.5b6af7b9884e1165...///` 支持设置域名 `/...whistle-path.5b6af7b9884e1165...///__domain__port__/path/to` (`port__` 可选) 或 `/...whistle-path.5b6af7b9884e1165...///path/to?_whistleInternalHost_=__domain__port__` (`port__` 可选)
68+
69+
# v2.6.9
70+
1. feat: 支持通过 `--shadowRules jsonString` 导入规则到 Rules
71+
2. style: 支持通过设置请求参数 `disabledEditor=1` 将 Rules & Values 编辑框设置为只读模式
72+
73+
# v2.6.8
74+
1. fix: `excludeFilter` `includeFilter` 混合配置时结果错乱问题
75+
2. feat: 支持 -M `rulesOnly``pluginsOnly`
76+
177
# v2.6.7
278
1. fix: https://github.com/avwo/whistle/issues/540
379

assets/js/log.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -327,26 +327,28 @@
327327
result = stringifyObj(result);
328328
result && addLog(level, result);
329329
};
330-
console[level] = function() {
331-
if (pending) {
332-
return;
333-
}
334-
pending = true;
335-
var weinreFn = console['_weinre_' + level];
336-
if (typeof weinreFn === 'function') {
330+
if ($INTERCEPT_CONSOLE) {
331+
console[level] = function() {
332+
if (pending) {
333+
return;
334+
}
335+
pending = true;
336+
var weinreFn = console['_weinre_' + level];
337+
if (typeof weinreFn === 'function') {
338+
try {
339+
weinreFn.apply(this, arguments);
340+
} catch (e) {}
341+
}
342+
wFn.apply(null, arguments);
337343
try {
338-
weinreFn.apply(this, arguments);
339-
} catch (e) {}
340-
}
341-
wFn.apply(null, arguments);
342-
try {
343-
fn.apply(this, arguments);
344-
} catch(e) {
345-
fn(arguments.length < 2 ? arguments[0] : slice.apply(arguments));
346-
} finally {
347-
pending = false;
348-
}
349-
};
344+
fn.apply(this, arguments);
345+
} catch(e) {
346+
fn(arguments.length < 2 ? arguments[0] : slice.apply(arguments));
347+
} finally {
348+
pending = false;
349+
}
350+
};
351+
}
350352
})(levels[i]);
351353
}
352354
/*eslint no-console: "off"*/
@@ -371,7 +373,7 @@
371373
var curConsole = window.console;
372374
if (!curConsole) {
373375
window.console = console;
374-
} else if (isWeinreConsole(curConsole)) {
376+
} else if ($INTERCEPT_CONSOLE && isWeinreConsole(curConsole)) {
375377
for (var i = 0, len = levels.length; i < len; i++) {
376378
var level = levels[i];
377379
var fn = console[level];

assets/launcher/mac/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Mac上配置开机重启whistle
2-
首先,下载Mac上的whistle脚步文件:[whistle.zip](https://github.com/avwo/whistle/raw/avenwu/assets/launcher/mac/whistle.zip)
2+
首先,下载Mac上的whistle脚步文件:[whistle.zip](https://github.com/avwo/whistle/blob/master/assets/launcher/mac/whistle.zip)
33

44
1. 解压whistle.zip获取whistle脚本文件,把该脚本文件拷贝一份到**应用程序**,打开桌面即可看到whistle这个脚本文件,这样可以直接在Mac的桌面上刊登whistle的启动脚本,点击该文件即可重启whistle;
55

bin/status.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function showAll() {
3030
++i;
3131
var options = conf.options;
3232
tips.push(' ' + i + '. port: ' + (options.port || pkg.port)
33+
+ (options.host ? ', host: ' + options.host : '')
3334
+ (options.storage ? ', storage: ' + options.storage : ''));
3435
});
3536
info(tips.join('\n'));

bin/use.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function existsPlugin(name) {
5151
var reqOptions;
5252
function request(body, callback) {
5353
if (!reqOptions) {
54-
reqOptions = url.parse('http://127.0.0.1:' + options.port + '/cgi-bin/rules/project');
54+
reqOptions = url.parse('http://' + (options.host || '127.0.0.1') + ':' + options.port + '/cgi-bin/rules/project');
5555
reqOptions.headers = {
5656
'content-type': 'application/x-www-form-urlencoded'
5757
};
@@ -113,7 +113,7 @@ module.exports = function(filepath, storage, force) {
113113
'rules=' + encodeURIComponent(rules)
114114
].join('&');
115115
request(body, function() {
116-
info('Setting whistle[127.0.0.1:' + port + '] rules successful.');
116+
info('Setting whistle[' + (options.host || '127.0.0.1') + ':' + port + '] rules successful.');
117117
});
118118
};
119119
if (force) {

bin/util.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ function showKillError() {
6262
exports.showKillError = showKillError;
6363

6464
function showUsage(isRunning, options, restart) {
65+
options = formatOptions(options);
6566
if (isRunning) {
6667
if (restart) {
6768
showKillError();
@@ -90,24 +91,31 @@ function showUsage(isRunning, options, restart) {
9091

9192
exports.showUsage = showUsage;
9293

93-
function getHomedir() {
94-
//默认设置为`~`,防止Linux在开机启动时Node无法获取homedir
95-
return (typeof os.homedir == 'function' ? os.homedir() :
96-
process.env[process.platform == 'win32' ? 'USERPROFILE' : 'HOME']) || '~';
94+
function getDataDir() {
95+
return path.resolve(config.getHomedir(), '.startingAppData');
9796
}
9897

99-
function getDataDir() {
100-
return path.resolve(getHomedir(), '.startingAppData');
98+
function formatOptions(options) {
99+
if (!options || !/^(?:([\w.-]+):)?([1-9]\d{0,4})$/.test(options.port)) {
100+
return options;
101+
}
102+
options.host = options.host || RegExp.$1;
103+
options.port = parseInt(RegExp.$2, 10);
104+
return options;
101105
}
102106

107+
exports.formatOptions = formatOptions;
108+
103109
function readConfig(storage) {
104110
var dataDir = getDataDir();
105111
var configFile = path.join(dataDir, encodeURIComponent('#' + (storage ? storage + '#' : '')));
106112
if (!fs.existsSync(configFile)) {
107113
return;
108114
}
109115
try {
110-
return fse.readJsonSync(configFile);
116+
var conf = fse.readJsonSync(configFile);
117+
conf && formatOptions(conf.options);
118+
return conf;
111119
} catch(e) {}
112120
}
113121

0 commit comments

Comments
 (0)