Permalink
Browse files

add webui express.io

  • Loading branch information...
1 parent 87a77e8 commit 0c28e1d5ca440a16ee9cea450b3f490f9173c385 @rehorn committed Apr 11, 2013
Showing 1,786 changed files with 354,699 additions and 4 deletions.
View
@@ -14,6 +14,7 @@ var httpServer, httpsServer, https2http;
var livepool = module.exports = {};
livepool.verson = '0.0.2';
livepool.startTime = (new Date()).getTime();
+var liveapp;
var config = liveRequire('config'),
logger = liveRequire('logger'),
@@ -55,9 +56,10 @@ livepool.run = function (){
var reqInfo = request.getReqInfo(req);
var handler = config.getHandler(reqInfo);
var reqUrl = reqInfo.url;
+ var hostname = reqInfo.headers.host.split(':')[0];
// local replacement
// console.log(handler)
- if(handler && (responder = responders[handler.respond.type])){
+ if((hostname != 'localhost') && handler && (responder = responders[handler.respond.type])){
logger.log('req handler [ ' + handler.respond.type.grey + ' ]: ' + reqUrl.grey);
responder(handler, req, res);
}else{
@@ -81,8 +83,14 @@ livepool.run = function (){
}).listen(httpsPort);
proxyHttps();
+
+ runLiveApp();
};
+function runLiveApp(){
+ liveapp = require('./webui/liveapp');
+}
+
// proxy https request from httpServer to httpsServer, stolen form nproxy
function proxyHttps() {
httpServer.on('connect', function(req, socket, upgradeHead) {
View
@@ -16,6 +16,7 @@ config.init = function (eventCenter){
config.global = {
http: 8000,
https: 8001,
+ uiport: 8002,
index: "index.html",
// proxy: "proxy.tencent.com:8080"
};
@@ -34,7 +34,9 @@ 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;
- logger.log('req proxied, host:' + host + ', port:' + port + ', url:' + req.url);
+ if(host !== 'localhost'){
+ logger.log('req proxied, host:' + host + ', port:' + port + ', url:' + req.url);
+ }
proxy.proxyRequest(req, res, {
host: host,
port: port
View
@@ -0,0 +1,42 @@
+var path = require('path'),
+ config = require('../livepool/config'),
+ logger = require('../livepool/logger');
+
+var routes = require('./routes');
+
+var uiport = config.global.uiport;
+
+var express = require('express.io');
+var liveapp = express();
+liveapp.http().io();
+
+var publicPath = __dirname + '/public',
+ viewPath = __dirname + '/views';
+
+liveapp.configure(function() {
+ liveapp.set('views', viewPath);
+ liveapp.set('basepath', publicPath);
+ liveapp.set('view engine', 'ejs');
+ liveapp.use(express.favicon());
+ liveapp.use(express.logger('dev'));
+ liveapp.use(express.bodyParser());
+ liveapp.use(express.methodOverride());
+ liveapp.use(liveapp.router);
+ routes(liveapp);
+});
+
+liveapp.configure('development', function(){
+ liveapp.use(express.static(publicPath));
+ liveapp.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
+});
+
+liveapp.configure('production', function(){
+ var oneYear = 31557600000;
+ liveapp.use(express.static(publicPath, { maxAge: oneYear }));
+ liveapp.use(express.errorHandler());
+});
+
+
+// build realtime-web app
+liveapp.listen(uiport);
+logger.log('liveapp ui'.cyan + ' is ready, port: ' + String(uiport).cyan);
No changes.
No changes.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
No changes.
No changes.
View
@@ -0,0 +1,24 @@
+
+var other = require('./other');
+
+
+var that = exports;
+
+exports.index = function(req, res) {
+ res.render('index');
+};
+
+module.exports = function(liveapp) {
+ // index page route and event
+ liveapp.io.route('ready', function(req) {
+ req.io.emit('talk', {
+ message: 'io event from an io route on the server'
+ })
+ })
+
+ liveapp.get('/', that.index);
+
+
+ // other page route and event
+ liveapp.get('/404', other.other);
+};
@@ -0,0 +1,4 @@
+
+exports.other = function(){
+
+}
@@ -0,0 +1,12 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <meta charset="UTF-8">
+ <title>Live Pool Client App</title>
+</head>
+<body>
+ Live Pool Client App
+ <script src="/socket.io/socket.io.js"></script>
+
+</body>
+</html>
View
@@ -1 +0,0 @@
-[object Object]
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 0c28e1d

Please sign in to comment.