Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
hzsrc committed Sep 5, 2017
1 parent 152da94 commit 1c169d8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
13 changes: 6 additions & 7 deletions config.js
@@ -1,13 +1,12 @@
const path = require('path');
module.exports = {
mockPath : process.argv[2] || './mockRoot', //模拟文件根目录
//proxyTarget : 'http://localhost:2011',//后台接口服务地址(代理目标)
proxyTarget : '',//后台接口服务地址(代理目标)
isHttps: false,
port : process.argv[3] || 8085, //端口
checkPath : function(urlPath) { //urlPath校验函数,返回true表示需要进行处理
mockPath : './mockRoot', //模拟文件根目录
proxyTarget : 'http://localhost:2011',//后台接口服务地址(代理目标),为空表示不代理
isHttps: false, //是否https
port : 8085, //端口
checkPath : function(urlPath) { //urlPath校验函数,返回true表示需要进行处理,为false直接走代理
if(urlPath.indexOf('/i/') > -1) return true
var ext = path.extname(urlPath);
return ext.indexOf('.as') == 0 || ext == '.axd' //aspx、ashx、asmx等
return /\.as\wx|\.axd|\.jsp/i.test(ext) //aspx、ashx、asmx、axd、jsp等
}
}
2 changes: 1 addition & 1 deletion create-server.js
Expand Up @@ -17,6 +17,6 @@ module.exports = function createServer(isHttps, port, onHandle){
http.createServer(options, onHandle).listen(port);
}
var url = "http"+(isHttps ? "s" : "")+"://localhost:" + port;
console.log("Static file server running at\n => "+url+"/\n " + "\nCTRL + C to shutdown");
console.log("Http server running at\n => " + url + "/\n " + "\nCTRL + C to shutdown");
//opn(url)
}
8 changes: 7 additions & 1 deletion index.js
Expand Up @@ -2,15 +2,21 @@ var path = require('path'), fs = require('fs');
var url = require('url'), querystring = require('querystring');
var yaml = require('js-yaml');
var createServer = require('./create-server.js')
var config =require('./config.js')
var config = (function(){
var fn = process.argv[2];
var fn = fn ? path.resolve(fn) : './config.js';
return require(fn);
}) ()

var proxy = require('http-proxy').createProxyServer({});
proxy.on('error', function (err, req, res, target) {
console.log("[ERROR]:" + req.url + "\t" + err.message)
res.end(err.message);
});
var _proxyHost = url.parse(config.proxyTarget).hostname;

//启动服务
console.log('Mock root path: ' + path.resolve(config.mockPath))
createServer(config.isHttps, config.port, onHandle);


Expand Down
3 changes: 2 additions & 1 deletion start.bat
@@ -1,6 +1,7 @@
rem netstat -ano | find "80"
taskkill /im node.exe

%~d0
cd %~dp0

node index.js
node index.js ./config.js

0 comments on commit 1c169d8

Please sign in to comment.