Permalink
Browse files

update

  • Loading branch information...
1 parent 0c28e1d commit 8ba1ed03533c454895f8a2a18277d3bedad58c78 @rehorn committed Apr 11, 2013
View
@@ -82,9 +82,11 @@ livepool.run = function (){
https2http.proxyRequest(req, res);
}).listen(httpsPort);
+
+ runLiveApp();
proxyHttps();
+ proxyWebSocket();
- runLiveApp();
};
function runLiveApp(){
@@ -131,6 +133,17 @@ 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);
+ });
+}
livepool.stop = function (){
if(httpSever){
@@ -26,17 +26,15 @@ function routeResponder(router, req, res){
}
}else{
// directly proxy
- goProxy(req, res, proxyAgent[0], proxyAgent[1]);
+ goProxy(req, res);
}
};
function goProxy(req, res, host, port){
var dhost = req.headers.host.split(':');
- host = host || dhost[0] || '127.0.0.1';
- port = port || dhost[1] || 80;
- if(host !== 'localhost'){
- logger.log('req proxied, host:' + host + ', port:' + port + ', url:' + req.url);
- }
+ 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
View
@@ -16,7 +16,7 @@ var publicPath = __dirname + '/public',
liveapp.configure(function() {
liveapp.set('views', viewPath);
liveapp.set('basepath', publicPath);
- liveapp.set('view engine', 'ejs');
+ // liveapp.set('view engine', 'ejs');
liveapp.use(express.favicon());
liveapp.use(express.logger('dev'));
liveapp.use(express.bodyParser());
@@ -36,7 +36,8 @@ liveapp.configure('production', function(){
liveapp.use(express.errorHandler());
});
-
// build realtime-web app
liveapp.listen(uiport);
+
+exports.app = liveapp;
logger.log('liveapp ui'.cyan + ' is ready, port: ' + String(uiport).cyan);
@@ -7,6 +7,14 @@
<body>
Live Pool Client App
<script src="/socket.io/socket.io.js"></script>
-
+ <script>
+ io = io.connect()
+ // Emit ready event.
+ io.emit('ready');
+ // Listen for the talk event.
+ io.on('talk', function(data) {
+ alert(data.message)
+ })
+ </script>
</body>
</html>
No changes.
@@ -1,11 +1,11 @@
+var path = require('path');
+var fs = require('fs');
var other = require('./other');
-
-
var that = exports;
exports.index = function(req, res) {
- res.render('index');
+ res.sendfile(path.join(__dirname, '../public/index.html'));
};
module.exports = function(liveapp) {
@@ -18,7 +18,6 @@ module.exports = function(liveapp) {
liveapp.get('/', that.index);
-
// other page route and event
liveapp.get('/404', other.other);
};
View
@@ -1,2 +1,2 @@
-exports = require('./lib/core');
+exports = require('./lib/core');

0 comments on commit 8ba1ed0

Please sign in to comment.