Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

http-proxy 1.0.1

  • Loading branch information...
commit a8cfe1b7e24c4bae48f15311938f4b75044193c3 1 parent c9ca4f4
@rehorn authored
View
1  .gitignore
@@ -0,0 +1 @@
+node_modules
View
52 lib/core.js
@@ -29,9 +29,9 @@ var global = config.global,
uiport = global.uiport,
proxyAgent = global.proxy || '',
proxyAgent = proxyAgent.split(':'),
- localName = 'localhost';
+ localName = '127.0.0.1';
-var proxy2Liveapp = new httpProxy.HttpProxy({
+var proxy2Liveapp = new httpProxy.createProxyServer({
target:{
host: localName,
port: uiport
@@ -66,10 +66,10 @@ livepool.run = function (){
var reqUrl = reqInfo.url;
var hostname = reqInfo.headers.host.split(':')[0];
console.log(req.url)
- if(reqUrl.match(/localhost:8002/)){
+ if(reqUrl.match(/127.0.0.1:8002/)){
// hack for express router & http-proxy
- req.url = req.url.replace('http://localhost:8002', '');
- proxy2Liveapp.proxyRequest(req, res);
+ // req.url = req.url.replace('http://localhost:8002', '');
+ proxy2Liveapp.web(req, res);
}else if((hostname != 'localhost') && handler && (responder = responders[handler.respond.type])){
// local replacement
logger.log('req handler [ ' + handler.respond.type.grey + ' ]: ' + reqUrl.grey);
@@ -82,18 +82,14 @@ livepool.run = function (){
}).listen(httpPort);
- https2http = new httpProxy.HttpProxy({
- target: {
- host: localName,
- port: httpPort
- }
- });
-
httpsServer = https.createServer(options, function (req, res){
console.log('https request proxied...');
- https2http.proxyRequest(req, res);
+ var proxy = httpProxy.createProxyServer({});
+ proxy.web(req, res, {
+ target: req.url,
+ ssl: options
+ });
}).listen(httpsPort);
-
runLiveApp();
proxyHttps();
@@ -150,10 +146,10 @@ function proxyWebSocket(){
httpServer.on('upgrade', function (req, socket, head) {
console.log('upgrade');
console.log(req.url)
- if(req.url.match(/localhost:8002/)){
+ if(req.url.match(/127.0.0.1:8002/)){
// hack for express router & http-proxy
- req.url = req.url.replace('http://localhost:8002', 'ws://localhost:8002');
- proxy2Liveapp.proxyWebSocketRequest(req, socket, head);
+ req.url = req.url.replace('http://127.0.0.1:8002', 'ws://127.0.0.1:8002');
+ proxy2Liveapp.ws(req, socket, head);
}
});
}
@@ -166,16 +162,16 @@ livepool.stop = function (){
livepool.run();
-process.stdin.resume();
-process.stdin.setEncoding('utf8');
+// process.stdin.resume();
+// process.stdin.setEncoding('utf8');
-process.stdin.on('data', function (chunk){
- if(chunk == "stop\r\n"){
- livepool.stop();
- process.exit(1);
- }
-});
+// process.stdin.on('data', function (chunk){
+// if(chunk == "stop\r\n"){
+// livepool.stop();
+// process.exit(1);
+// }
+// });
-process.stdin.on('end', function () {
- process.stdout.write('end');
-});
+// process.stdin.on('end', function () {
+// process.stdout.write('end');
+// });
View
4 lib/livepool/config.js
@@ -14,11 +14,11 @@ config.init = function (eventCenter){
};
config.global = {
- http: 8000,
+ http: 8090,
https: 8001,
uiport: 8002,
index: "index.html",
- proxy: "proxy.tencent.com:8080"
+ // proxy: "proxy.tencent.com:8080"
};
var ruleGroup = {
View
18 lib/livepool/logger.js
@@ -106,15 +106,15 @@ var _onExit = function() {
process.on('exit', _onExit);
process.on('uncaughtException', function(err) {
- // exports.error(err.stack || err);
+ // // exports.error(err.stack || err);
exports.error('uncaughtException: ' + (err.stack || err));
- // exports.error('uncaughtException: ' + err);
+ // // exports.error('uncaughtException: ' + err);
- try{
- fs.appendFile('log/log.txt', '\r\n' + (err.stack || err), function (err) {
- if (err) throw err;
- });
- }catch(e){
- exports.error(e);
- }
+ // try{
+ // fs.appendFile('log/log.txt', '\r\n' + (err.stack || err), function (err) {
+ // if (err) throw err;
+ // });
+ // }catch(e){
+ // exports.error(e);
+ // }
});
View
1  lib/livepool/responder/qzmin.js
@@ -23,6 +23,7 @@ function respond404(res){
function qzminResponder(handler, req, res) {
var qzminFilepath = path.join(handler.base, handler.actionRaw);
+ // console.log(qzminFilepath)
if(!fs.existsSync(qzminFilepath)){
respond404(res);
return ;
View
16 lib/livepool/responder/route.js
@@ -4,7 +4,6 @@ var config = require('../config'),
logger = require('../logger');
var httpProxy = require('http-proxy');
-var proxy = new httpProxy.RoutingProxy();
var global = config.global,
proxyAgent = global.proxy || '',
@@ -35,10 +34,17 @@ function goProxy(req, res, host, port){
host = proxyAgent[0] || host || dhost[0] || '127.0.0.1';
port = proxyAgent[1] || port || dhost[1] || 80;
logger.log('req proxied, host:' + host + ', port:' + port + ', url:' + req.url);
- proxy.proxyRequest(req, res, {
- host: host,
- port: port
- });
+ // proxy.proxyRequest(req, res, {
+ // host: host,
+ // port: port
+ // });
+ var proxy = httpProxy.createProxyServer({});
+ proxy.web(req, res, {
+ target: {
+ host: host,
+ port: port
+ }
+ });
};
module.exports = routeResponder;
View
11 lib/webui/public/index.html
@@ -3,13 +3,16 @@
<head>
<meta charset="UTF-8">
<title>Live Pool Client App</title>
- <link rel="stylesheet" type="text/css" href="vendor/extjs4/resources/css/ext-all.css" />
- <link rel="stylesheet" type="text/css" href="css/liveapp.css" />
+ <link rel="stylesheet" type="text/css" href="/libs/ext-theme/Azzurra/css/azzurra/azzurra-core.css">
+ <link rel="stylesheet" type="text/css" href="/libs/ext-theme/Azzurra/css/azzurra/azzurra-ui-all.css">
+ <link rel="stylesheet" type="text/css" href="/libs/icomoon/sprites.css">
+ <link rel="stylesheet" type="text/css" href="/css/main.css" />
+ <script type="text/javascript" src="/libs/ext/ext-all.js"></script>
+ <script type="text/javascript" src="/libs/ext-theme/Azzurra/js/azzurra.js"></script>
</head>
<body>
- <script type="text/javascript" src="vendor/extjs4/ext-all.js"></script>
- <script type="text/javascript" src="js/liveapp.js"></script>
+ <script type="text/javascript" src="/js/liveapp.js"></script>
<script src="/socket.io/socket.io.js"></script>
<script>
io = io.connect();
View
16 lib/webui/public/js/liveapp.js
@@ -1,8 +1,8 @@
-Ext.Loader.setConfig({enabled: true});
-Ext.application({
- name: 'LiveApp',
- appFolder: 'js',
- controllers: [
- 'Main'
- ]
-});
+// Ext.Loader.setConfig({enabled: true});
+// Ext.application({
+// name: 'LiveApp',
+// appFolder: 'js',
+// controllers: [
+// 'Main'
+// ]
+// });
View
1  lib/webui/routes/index.js
@@ -5,6 +5,7 @@ var other = require('./other');
var that = exports;
exports.index = function(req, res) {
+ console.log(1)
res.sendfile(path.join(__dirname, '../public/index.html'));
};
View
5 package.json
@@ -13,10 +13,7 @@
"http-proxy": "*",
"mime": "*",
"underscore": "*",
- "ejs": "*"
- },
- "devDependencies": {
- "nodemon": "*"
+ "ejs": "*"
},
"repository": {
"type": "git",
View
76 rules/project1.js
@@ -1,38 +1,38 @@
-module.exports = {
- name: "project1",
- // index: 0, // default is 0
- // enabled: 1, // default is 1
- base: "E:/git/livepool/test/examples/",
- handler: [{
- // test => http://www.livepool.com/index.html
- match: "www.livepool.com/index.html",
- action: "./__index.html"
- // enabled: 1 // default is 1
- }, {
- // test => http://www.livepool.com/static-web/site/index.html
- // test => http://www.livepool.com/static-web/index.html
- match: "www.livepool.com/static-web/",
- action: "./static/"
- }, {
- // test => http://www.livepool.com/js/chat.all.js
- match: "www.livepool.com/js/chat.all.js",
- action: "./tools/chat.all.qzmin"
- }, {
- // test => http://www.livepool.com/css/main.css
- match: "www.livepool.com/css/main.css",
- action: ["./css/sub1.css", "./css/sub2.css"]
- }, {
- match: "www.livepool.com/css/remote.css",
- action: "http://chat.qq.com/css/remote2.css"
- }, {
- match: "www.livepool.com/ *.cdn.livepool.cn/examples/",
- action: "./"
- }],
- router: [{
- match: "www.livepool.com/cgi-bin/ srv.livepool.com/",
- action: "-"
- }, {
- match: "www.livepool.com",
- action: "127.0.0.1"
- }]
-};
+// module.exports = {
+// name: "project1",
+// // index: 0, // default is 0
+// // enabled: 1, // default is 1
+// base: "E:/git/livepool/test/examples/",
+// handler: [{
+// // test => http://www.livepool.com/index.html
+// match: "www.livepool.com/index.html",
+// action: "./__index.html"
+// // enabled: 1 // default is 1
+// }, {
+// // test => http://www.livepool.com/static-web/site/index.html
+// // test => http://www.livepool.com/static-web/index.html
+// match: "www.livepool.com/static-web/",
+// action: "./static/"
+// }, {
+// // test => http://www.livepool.com/js/chat.all.js
+// match: "www.livepool.com/js/chat.all.js",
+// action: "./tools/chat.all.qzmin"
+// }, {
+// // test => http://www.livepool.com/css/main.css
+// match: "www.livepool.com/css/main.css",
+// action: ["./css/sub1.css", "./css/sub2.css"]
+// }, {
+// match: "www.livepool.com/css/remote.css",
+// action: "http://chat.qq.com/css/remote2.css"
+// }, {
+// match: "www.livepool.com/ *.cdn.livepool.cn/examples/",
+// action: "./"
+// }],
+// router: [{
+// match: "www.livepool.com/cgi-bin/ srv.livepool.com/",
+// action: "-"
+// }, {
+// match: "www.livepool.com",
+// action: "127.0.0.1"
+// }]
+// };
View
54 rules/project2.js
@@ -1,27 +1,27 @@
-module.exports = {
- name: "project2",
- base: "E:/connect/bapp/qqfind_v2/",
- handler: [{
- match: "find.qq.com/index.html",
- action: "./__index.html"
- }, {
- match: "find.qq.com/js/find.all.js",
- action: "./tools/find.all.js.qzmin"
- }, {
- match: "find.qq.com/css/comp.css",
- action: ["./css/loading.css", "./css/tab.css"]
- }, {
- match: "find.qq.com/js/catalog.js",
- action: "http://pub.idqqimg.com/qqfind/js/groupcatalog.js"
- }, {
- match: "find.qq.com/ *.idqqimg.com/qqfind/",
- action: "./"
- }],
- router: [{
- match: "find.qq.com/cgi-bin/ cgi.find.qq.com",
- action: "-"
- }, {
- match: "find.qq.com idqqimg.com/qqfind/",
- action: "172.23.136.84"
- }]
-};
+// module.exports = {
+// name: "project2",
+// base: "E:/connect/bapp/qqfind_v2/",
+// handler: [{
+// match: "find.qq.com/index.html",
+// action: "./__index.html"
+// }, {
+// match: "find.qq.com/js/find.all.js",
+// action: "./tools/find.all.js.qzmin"
+// }, {
+// match: "find.qq.com/css/comp.css",
+// action: ["./css/loading.css", "./css/tab.css"]
+// }, {
+// match: "find.qq.com/js/catalog.js",
+// action: "http://pub.idqqimg.com/qqfind/js/groupcatalog.js"
+// }, {
+// match: "find.qq.com/ *.idqqimg.com/qqfind/",
+// action: "./"
+// }],
+// router: [{
+// match: "find.qq.com/cgi-bin/ cgi.find.qq.com",
+// action: "-"
+// }, {
+// match: "find.qq.com idqqimg.com/qqfind/",
+// action: "172.23.136.84"
+// }]
+// };
View
30 rules/project3.js
@@ -0,0 +1,30 @@
+module.exports = {
+ name: "project3",
+ base: "/Users/rehorn/Documents/Code/node/livepool/test/examples/",
+ handler: [{
+ match: "find.qq.com/index.html",
+ action: "./__index.html"
+ }, {
+ match: "find.qq.com/js/find.all.js",
+ action: "./tools/find.all.qzmin"
+ }, {
+ match: "find.qq.com/js/find.combo.js",
+ action: ["./js/jquery.js", "./js/main.js"]
+ }, {
+ match: "find.qq.com/css/comp.css",
+ action: ["./css/main.css", "./css/sub1.css"]
+ }, {
+ match: "find.qq.com/js/catalog.js",
+ action: "http://pub.idqqimg.com/qqfind/js/groupcatalog.js"
+ }, {
+ match: "find.qq.com/ *.idqqimg.com/qqfind/",
+ action: "./"
+ }],
+ router: [{
+ match: "find.qq.com/cgi-bin/ cgi.find.qq.com",
+ action: "-"
+ }, {
+ match: "find.qq.com idqqimg.com/qqfind/",
+ action: "172.23.136.84"
+ }]
+};
View
120 test.js
@@ -3,36 +3,118 @@ var fs = require('fs'),
https = require('https'),
httpProxy = require('http-proxy');
+var net = require('net');
+
var options = {
https: {
- key: fs.readFileSync('lib/keys/key.pem', 'utf8'),
- cert: fs.readFileSync('lib/keys/cert.pem', 'utf8')
+ key: fs.readFileSync('keys/CA.crt', 'utf8'),
+ cert: fs.readFileSync('keys/cacert.pem', 'utf8')
}
};
-//
-// Create a standalone HTTPS proxy server
-//
-httpProxy.createServer(8000, 'localhost', options).listen(8001);
+// var server = require('http').createServer(function(req, res) {
+// var proxy = httpProxy.createProxyServer({});
+// proxy.web(req, res, {
+// target: req.url
+// });
+// }).listen(8090);
+
+// proxyHttps();
+
+// // proxy https request from httpServer to httpsServer, stolen form nproxy
+// function proxyHttps() {
+// server.on('connect', function(req, socket, upgradeHead) {
+// console.log(req.method)
+// var netClient = net.createConnection(8091);
+
+// netClient.on('connect', function() {
+// // logger.info('connect to https server successfully!');
+// socket.write("HTTP/1.1 200 Connection established\r\nProxy-agent: Netscape-Proxy/1.1\r\n\r\n");
+// });
+
+// socket.on('data', function(chunk) {
+// netClient.write(chunk);
+// });
+// socket.on('end', function() {
+// netClient.end();
+// });
+// socket.on('close', function() {
+// netClient.end();
+// });
+// socket.on('error', function(err) {
+// // logger.error('socket error ' + err.message);
+// netClient.end();
+// });
+
+// netClient.on('data', function(chunk) {
+// socket.write(chunk);
+// });
+// netClient.on('end', function() {
+// socket.end();
+// });
+// netClient.on('close', function() {
+// socket.end();
+// });
+// netClient.on('error', function(err) {
+// // logger.error('netClient error ' + err.message);
+// socket.end();
+// });
+// });
+// };
+
+// var httpsServer = https.createServer(options.https, function (req, res){
+// console.log('https request proxied...');
+// // https2http.proxyRequest(req, res);
+// var proxy = httpProxy.createProxyServer({});
+// proxy.web(req, res, {
+// target: req.url,
+// ssl: options.https
+// });
+// }).listen(8091);
+
+// server.on('connect', function(req, res, head){
+// // var proxy = httpProxy.createProxyServer({});
+// // proxy.web(req, res, {
+// // target: req.url,
+// // ssl: options.ssl
+// // });
+
+// });
+
+// httpProxy.createProxyServer({
+// target:'http://localhost:9000',
+// // ssl:options.https,
+// // ws:true,
+// // secure:true
+// }).listen(8090);
+// http.createServer(function (req, res) {
+// console.log(req.url);
+// // res.writeHead(200, { 'Content-Type': 'text/plain' });
+// // res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
+// // res.end();
+// var proxy = httpProxy.createProxyServer({});
+// proxy.web(req, res, {
+// target: req.url
+// });
+// }).listen(9000);
+
+var http = require('http'),
+ httpProxy = require('http-proxy');
//
-// Create an instance of HttpProxy to use with another HTTPS server
+// Create your proxy server and set the target in the options.
//
-var proxy = new httpProxy.HttpProxy({
- target: {
- host: 'localhost',
- port: 8000
- }
-});
-https.createServer(options.https, function (req, res) {
- proxy.proxyRequest(req, res)
-}).listen(8002);
+httpProxy.createProxyServer({target:'http://localhost:9000'}).listen(8090);
//
-// Create the target HTTPS server for both cases
+// Create your target server
//
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
- res.write('hello https\n');
+ res.write('request successfully proxied!' + '\n' + JSON.stringify(req.headers, true, 2));
res.end();
-}).listen(8000);
+}).listen(9000);
+
+process.on('uncaughtException', function(err) {
+ console.log('uncaughtException: ' + (err.stack || err));
+});
View
13 test/examples/css/comp.css
@@ -0,0 +1,13 @@
+#test{
+ color: red;
+}
+#test2{
+ color: yellow;
+}
+
+#test3{
+ color: red;
+}
+#test{
+ color: red;
+}
View
7 test/examples/js/find.combo.js
@@ -0,0 +1,7 @@
+function(){
+ return true;
+}
+function(){
+ // updated 2
+ return true;
+}
View
4 test/examples/tools/chat.all.js → test/examples/tools/find.all.js
@@ -1,10 +1,10 @@
function(){
return true;
-}
+}
function(){
// updated 2
return true;
-}
+}
function(){
return true;
}
View
2  test/examples/tools/chat.all.qzmin → test/examples/tools/find.all.qzmin
@@ -2,7 +2,7 @@
projects: [
{
name: "Jx Custom Version for Q+ Explorer",
- target: "./chat.all.js",
+ target: "./find.all.js",
include: [
'../js/jquery.js',
'../js/main.js',
Please sign in to comment.
Something went wrong with that request. Please try again.