Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

httproxy websocket

  • Loading branch information...
commit 1f17e45080625e8b476812d2924c93c29d7a1944 1 parent 8ba1ed0
@rehorn authored
Showing with 21 additions and 13 deletions.
  1. +17 −12 lib/core.js
  2. +1 −1  lib/livepool/config.js
  3. +3 −0  lib/webui/readme.md
View
29 lib/core.js
@@ -26,10 +26,18 @@ var config = liveRequire('config'),
var global = config.global,
httpPort = global.http,
httpsPort = global.https,
+ uiport = global.uiport,
proxyAgent = global.proxy || '',
proxyAgent = proxyAgent.split(':'),
localName = 'localhost';
+var proxy2Liveapp = new httpProxy.HttpProxy({
+ target:{
+ host: localName,
+ port: uiport
+ }
+});
+
function publish(source, methodName, newMethodName) {
livepool[newMethodName || methodName] = source[methodName].bind(source);
}
@@ -57,9 +65,12 @@ livepool.run = function (){
var handler = config.getHandler(reqInfo);
var reqUrl = reqInfo.url;
var hostname = reqInfo.headers.host.split(':')[0];
- // local replacement
- // console.log(handler)
- if((hostname != 'localhost') && handler && (responder = responders[handler.respond.type])){
+ if(reqUrl.match(/localhost:8002/)){
+ // hack for express router & http-proxy
+ req.url = req.url.replace('http://localhost:8002', '');
+ proxy2Liveapp.proxyRequest(req, res);
+ }else if((hostname != 'localhost') && handler && (responder = responders[handler.respond.type])){
+ // local replacement
logger.log('req handler [ ' + handler.respond.type.grey + ' ]: ' + reqUrl.grey);
responder(handler, req, res);
}else{
@@ -86,7 +97,6 @@ livepool.run = function (){
runLiveApp();
proxyHttps();
proxyWebSocket();
-
};
function runLiveApp(){
@@ -99,7 +109,7 @@ function proxyHttps() {
var netClient = net.createConnection(httpsPort);
netClient.on('connect', function() {
- // logger.info('connect to https server successfully!');
+ 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");
});
@@ -133,15 +143,10 @@ function proxyHttps() {
});
};
-var app = new httpProxy.HttpProxy({
- target: {
- host: 'localhost',
- port: 8002
- }
-});
+
function proxyWebSocket(){
httpServer.on('upgrade', function (req, socket, head) {
- app.proxyWebSocketRequest(req, socket, head);
+ proxy2Liveapp.proxyWebSocketRequest(req, socket, head);
});
}
View
2  lib/livepool/config.js
@@ -18,7 +18,7 @@ config.global = {
https: 8001,
uiport: 8002,
index: "index.html",
- // proxy: "proxy.tencent.com:8080"
+ proxy: "proxy.tencent.com:8080"
};
var ruleGroup = {
View
3  lib/webui/readme.md
@@ -0,0 +1,3 @@
+### liveapp is web gui for livepool
+
+bug to fix: liveapp must not be visited through livepool proxy port(8000), must visit directly.
Please sign in to comment.
Something went wrong with that request. Please try again.