mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-06-24 12:18:54 +00:00
65 lines
2.2 KiB
Plaintext
65 lines
2.2 KiB
Plaintext
diff --git a/bin.js b/bin.js
|
|
index 9b7f39b..86ccdee 100644
|
|
--- a/bin.js
|
|
+++ b/bin.js
|
|
@@ -4,6 +4,7 @@ var program = require('commander'),
|
|
proxy = require("./proxy.js"),
|
|
color = require('colorful'),
|
|
fs = require("fs"),
|
|
+ path = require("path"),
|
|
packageInfo = require("./package.json");
|
|
|
|
program
|
|
@@ -33,15 +34,16 @@ if(program.clear){
|
|
var ruleModule;
|
|
|
|
if(program.rule){
|
|
- if(fs.existsSync(program.rule)){
|
|
- try{ //for abs path
|
|
+ var ruleFilePath = path.join(process.cwd(),program.rule);
|
|
+ try{
|
|
+ if(fs.existsSync(ruleFilePath)){
|
|
ruleModule = require(program.rule);
|
|
- }catch(e){ //for relative path
|
|
- ruleModule = require(process.cwd() + '/' + program.rule.replace(/^\.\//,''));
|
|
+ console.log("rule file loaded :" + ruleFilePath);
|
|
+ }else{
|
|
+ console.log(color.red("can not find rule file"));
|
|
}
|
|
- console.log(color.green("rule file loaded"));
|
|
- }else{
|
|
- console.log(color.red("can not find rule file"));
|
|
+ }catch(e){
|
|
+ console.log("failed to load rule file :" + e.toString());
|
|
}
|
|
}
|
|
|
|
diff --git a/lib/requestHandler.js b/lib/requestHandler.js
|
|
index 37f19d4..620b7f9 100644
|
|
--- a/lib/requestHandler.js
|
|
+++ b/lib/requestHandler.js
|
|
@@ -364,7 +364,7 @@ function setRules(newRule){
|
|
}
|
|
if('function' == typeof(userRule.summary)){
|
|
functions.push(function(cb){
|
|
- userRule.summary();
|
|
+ console.log(userRule.summary());
|
|
cb(null);
|
|
});
|
|
}
|
|
diff --git a/rule_sample/README.md b/rule_sample/README.md
|
|
index 7a8eabb..7c29ff5 100644
|
|
--- a/rule_sample/README.md
|
|
+++ b/rule_sample/README.md
|
|
@@ -27,6 +27,9 @@ The following are sample rules.
|
|
* rule_replace_response_status_code.js
|
|
* replace server's status code
|
|
* 改变服务端响应的http状态码
|
|
+* rule_reverse_proxy.js
|
|
+ * assign a specific ip address for request
|
|
+ * 为请求绑定目标ip
|
|
* rule_use_local_data.js
|
|
* map some requests to local file
|
|
* 把图片响应映射到本地
|
|
\ No newline at end of file
|