mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-07-27 07:45:41 +00:00
improve file mapping
This commit is contained in:
@@ -27,7 +27,7 @@ var handleRule = {
|
||||
|
||||
function userRequestHandler(req,userRes){
|
||||
var host = req.headers.host,
|
||||
path = url.parse(req.url).path,
|
||||
path = url.parse(req.url).pathname,
|
||||
ifLocalruleMatched = false;
|
||||
|
||||
console.log(color.green("\nreceived request to : " + host + path));
|
||||
@@ -47,10 +47,11 @@ function userRequestHandler(req,userRes){
|
||||
console.log("==>meet the rules, will map to local file");
|
||||
|
||||
var targetLocalfile = rule.localFile;
|
||||
if(!targetLocalfile){ //find file in dir //TODO : /a/b/c -> b/c
|
||||
var basename = pathUtil.basename(path);
|
||||
basename = basename.slice(0,basename.indexOf("?")); //remove chars after question mark
|
||||
targetLocalfile = pathUtil.join(rule.localDir,basename);
|
||||
|
||||
//localfile not set, map to dir
|
||||
if(!targetLocalfile){ //find file in dir, /a/b/file.html -> dir + b/file.html
|
||||
var remotePathWithoutPrefix = path.replace(new RegExp(rule.path),""); //remove prefix
|
||||
targetLocalfile = pathUtil.join(rule.localDir,remotePathWithoutPrefix);
|
||||
}
|
||||
|
||||
console.log("==>local file: " + targetLocalfile);
|
||||
|
Reference in New Issue
Block a user