mirror of
https://github.com/alibaba/anyproxy.git
synced 2025-05-18 12:58:26 +00:00
fix fs exists problem
This commit is contained in:
parent
ead766bdbe
commit
ed09e35145
17
index.js
17
index.js
@ -1,3 +1,5 @@
|
|||||||
|
var PROXY_PORT = 8001;
|
||||||
|
|
||||||
var http = require('http'),
|
var http = require('http'),
|
||||||
https = require('https'),
|
https = require('https'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
@ -11,11 +13,11 @@ var serverMgrInstance = new serverMgr();
|
|||||||
var httpProxyServer = http.createServer(function (req, res) {
|
var httpProxyServer = http.createServer(function (req, res) {
|
||||||
var urlPattern = url.parse(req.url);
|
var urlPattern = url.parse(req.url);
|
||||||
var options = {
|
var options = {
|
||||||
hostname: urlPattern.host,
|
hostname : urlPattern.host,
|
||||||
port: urlPattern.port || 80,
|
port : urlPattern.port || 80,
|
||||||
path: urlPattern.path,
|
path : urlPattern.path,
|
||||||
method: req.method,
|
method : req.method,
|
||||||
headers:req.headers
|
headers : req.headers
|
||||||
};
|
};
|
||||||
|
|
||||||
var directReq = http.request(options,function(directRes){
|
var directReq = http.request(options,function(directRes){
|
||||||
@ -46,7 +48,7 @@ httpProxyServer.on('connect', function(req, socket, head){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}catch(e){
|
}catch(e){
|
||||||
console.log("err --");//TODO
|
console.log("err when connect to local https server (__hostname)".replace(/__hostname/,hostname));//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
@ -55,4 +57,5 @@ httpProxyServer.on('connect', function(req, socket, head){
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
httpProxyServer.listen(8001);
|
httpProxyServer.listen(PROXY_PORT);
|
||||||
|
console.log("proxy started at port " + PROXY_PORT);
|
@ -8,6 +8,10 @@ var getPort = require('./getPort'),
|
|||||||
url = require('url'),
|
url = require('url'),
|
||||||
exec = require('child_process').exec;
|
exec = require('child_process').exec;
|
||||||
|
|
||||||
|
if(!fs.exists("cert/tmpCert")){
|
||||||
|
fs.mkdir("cert/tmpCert");
|
||||||
|
}
|
||||||
|
|
||||||
module.exports =function(){
|
module.exports =function(){
|
||||||
var self = this;
|
var self = this;
|
||||||
self.serverList = {
|
self.serverList = {
|
||||||
@ -31,7 +35,6 @@ module.exports =function(){
|
|||||||
|
|
||||||
//create server with corresponding CA
|
//create server with corresponding CA
|
||||||
}else{
|
}else{
|
||||||
fs.mkdir("cert/tmpCert");
|
|
||||||
var keyFile = "./cert/tmpCert/__hostname.key".replace(/__hostname/,hostname),
|
var keyFile = "./cert/tmpCert/__hostname.key".replace(/__hostname/,hostname),
|
||||||
crtFile = "./cert/tmpCert/__hostname.crt".replace(/__hostname/,hostname);
|
crtFile = "./cert/tmpCert/__hostname.crt".replace(/__hostname/,hostname);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user