Skip to content

Commit

Permalink
change realtime port for the production server
Browse files Browse the repository at this point in the history
  • Loading branch information
janmonschke committed Jan 24, 2013
1 parent cd0faf7 commit 3f4254d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
12 changes: 9 additions & 3 deletions app/initialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ $(function() {

// start socket.io only when the user is logged in
if(user.isLoggedIn()){
// hotfix for missing socket
window.socket = io.connect();
// connect the socket
// decide on location of the socket server
var socketServer = '';
if(window.realtimePort)
socketServer = location.host + ':' + window.realtimePort;
else
socketServer = '127.0.0.1:3000';

// connect to the socket
window.socket = io.connect(socketServer);
socket.on('connect', function(){
// register the socket to the server
socket.emit('register_socket', user.id);
Expand Down
10 changes: 6 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ app.configure(function(){

/** TODO: find out why res.redirect('/') is not working on uberhost */
var baseURL = (process.env['NODE_ENV'] === 'production') ? 'http://speculos.taurus.uberspace.de' : '';
var realtimePort = (process.env['NODE_ENV'] === 'production') ? 51584 : false;

/** Performs general routing actions */
var routeHandler = {

/** Simply renders the index */
renderIndex: function(req, res){
res.render('index', { user: (req.user || null), lockedModels: lockedModels });
res.render('index', { user: (req.user || null), lockedModels: lockedModels, realtimePort: realtimePort });
},

/** Redirects to the login when the user is not logged in */
Expand All @@ -84,7 +85,7 @@ var routeHandler = {
var user = {};
user._id = req.user.id;
user._rev = req.user._rev;
res.render('index', { user: user, lockedModels: lockedModels });
res.render('index', { user: user, lockedModels: lockedModels, realtimePort: realtimePort });
}else{
res.redirect(baseURL + '/login?forward_to=' + req.url.split('/').join('__'));
}
Expand All @@ -95,7 +96,7 @@ var routeHandler = {
if(req.user){
res.redirect(baseURL + '/edit');
}else{
res.render('index', { user: null, lockedModels: lockedModels });
res.render('index', { user: null, lockedModels: lockedModels, realtimePort: realtimePort });
}
}
};
Expand Down Expand Up @@ -244,7 +245,8 @@ console.log('Server is up and running on port: ' + port);
var lockedModels = [];

// Realtime stuff
var io = io.listen(server);
var io = (process.env.NODE_ENV == 'production') ? io.listen(51584) : io.listen(server);

// a less noisy log level
io.set('log level', 1)

Expand Down
5 changes: 4 additions & 1 deletion server/views/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ html
script(src="/socket.io/socket.io.js")
title CGIP
body
script(id="lockedModels")
script(id="lm")
window.lockedModels = !{JSON.stringify(lockedModels)};
scrip(id="rp")
window.realtimePort = !{realtimePort};

if user
script(id="user_hash")
window.user_hash = !{JSON.stringify(user)};
Expand Down

0 comments on commit 3f4254d

Please sign in to comment.