Skip to content

Commit

Permalink
调整windows下启动逻辑,去掉探测请求判断
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyoukun committed May 24, 2018
1 parent 55978ab commit ad8ebc2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 61 deletions.
71 changes: 11 additions & 60 deletions bin/proxy/http.proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ const cp = require('child_process');
const parseGet = require('util/http/parseGet.js');
const tnm2 = require('api/tnm2');
const cpuUtil = require('util/cpu.js');
const httpUtil = require('util/http.js');
const TEReport = require('util/auto-report/TEReport.js');
const mail = require('util/mail/mail.js');
const websocket = require('./websocket.js');
Expand All @@ -35,14 +34,14 @@ const serverInfo = {
intranetIp: require('serverInfo.js').intranetIp,
cpu: 'X'
};
var server;
var serverThis;
var serverHttps;
var config = require('./config.js');
var routeCache = null;
var cleanCacheTid = null;
var isStartHeartBeat = false;
var heartBeatCount = 0;
let server;
let serverThis;
let serverHttps;
let config = require('./config.js');
let routeCache = null;
let cleanCacheTid = null;
let isStartHeartBeat = false;
let heartBeatCount = 0;


function doRoute(req,res){
Expand All @@ -52,57 +51,12 @@ function doRoute(req,res){
config = require('./config.js');
}

if(req.headers['user-agent'] === 'nws' && req.headers.host === serverInfo.intranetIp){
//nws探测请求
res.writeHead(200, {'Content-Type': 'text/html; charset=UTF-8'});
res.end('hello nws');

return;
}

if(req.headers['user-agent'] === 'TgwProbe'){
//stgw探测请求
res.writeHead(200, {'Content-Type': 'text/html; charset=UTF-8'});
res.end('hello TgwProbe');

return;
}

if(req.headers['user-agent'] === 'StgwProbe'){
//stgw探测请求
res.writeHead(200, {'Content-Type': 'text/html; charset=UTF-8'});
res.end('hello StgwProbe');

return;
}

if(req.headers['user-agent'] === 'TgwProbe'){
//stgw探测请求
res.writeHead(200, {'Content-Type': 'text/html; charset=UTF-8'});
res.end('hello TgwProbe');

return;
}

if(req.REQUEST.pathname === '/' && !req.headers['user-agent']){

if(httpUtil.isInnerIP(httpUtil.getUserIp(req))){
//l7探测请求
res.writeHead(200, {'Content-Type': 'text/html; charset=UTF-8'});
res.end('hello l7');
return;
}

}

routeCache(req,res);
}

process.serverInfo = serverInfo;

/**
* 清除缓存
*/
//清除缓存
function cleanCache(){

clearTimeout(cleanCacheTid);
Expand All @@ -127,7 +81,7 @@ process.on('heapdump',function(e){

require('heapdump').writeSnapshot(__dirname + '/cpu' + serverInfo.cpu + '.' + Date.now() + '.heapsnapshot',function(err, filename) {
logger.info('dump written to ${filename}', {
filename: filename
filenamelet: filename
});
});

Expand Down Expand Up @@ -540,10 +494,7 @@ methodMap.listen = function(message){
};

if(cluster.isMaster){
if(isWindows){
logger.info('isWindows, start listening');
methodMap.listen({cpu : 0});
}else if(debugOptions && debugOptions.inspectorEnabled){
if(debugOptions && debugOptions.inspectorEnabled){
logger.setLogLevel('debug');
logger.info('inspectorEnabled, start listening');
methodMap.listen({cpu : 0});
Expand Down
2 changes: 1 addition & 1 deletion bin/proxy/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function startServer(){

}else{

//子进程直接引入proxy文件,当然也可以直接在这里写逻辑运行,注意此处else作用域属于子进程作用域,非本程序作用域
//子进程直接引入proxy文件,注意此处else作用域属于子进程作用域,非本程序作用域
process.title = 'TSW/worker/node';
logger.info('start worker....');
require('./http.proxy.js');
Expand Down

0 comments on commit ad8ebc2

Please sign in to comment.