Skip to content

Commit

Permalink
more prod vs nonprod configs
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentwoo committed Apr 13, 2012
1 parent a11f49e commit 1e6ecef
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
22 changes: 8 additions & 14 deletions client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ var socket
, preventRefresh = false
, fixwrap
, SERVER_EVENTS = ['init', 'join', 'leave', 'rejoin', 'taken', 'setHash', 'remaining', 'puzzled',
'add', 'hint', 'start', 'win', 'msg'];
'add', 'hint', 'start', 'win', 'msg', 'disconnect', 'reconnect', 'reconnecting',
'reconnect_failed'];

$(function() {
fixwrap = $('#fixwrap');
Expand All @@ -17,10 +18,8 @@ $(function() {
});

function startGame() {
socket = io.connect(null, {
rememberTransport: true
, transports: ['websocket', 'flashsocket', 'xhr-multipart', 'xhr-polling', 'jsonp-polling']
});
socket = io.connect();

socket.on('connect', function() {
$('#announcement').html('<h1>Connected!</h1>');
$('#announcement').removeClass('loading');
Expand All @@ -34,11 +33,6 @@ function startGame() {
SERVER_EVENTS.forEach(function(event) {
socket.on(event, window[event]);
});

socket.on('disconnect', socket_disconnect);
socket.on('reconnect', socket_reconnect);
socket.on('reconnecting', socket_reconnect);
socket.on('reconnect_failed', socket_reconnect_failed);

$('#hint').click(requestHint);
$('#input').keydown(input);
Expand Down Expand Up @@ -430,15 +424,15 @@ function initGame() {
socket.emit('init', init);
}

function socket_disconnect() {
function disconnect() {
msg({event:true, msg: 'You have been disconnected'})
}
function socket_reconnect() {
function reconnect() {
msg({event:true, msg: 'Reconnected to server'})
}
function socket_reconnecting(nextRetry) {
function reconnecting(nextRetry) {
msg({event:true, msg: ('Attempting to re-connect to the server, next attempt in ' + nextRetry + 'ms')})
}
function socket_reconnect_failed() {
function reconnect_failed() {
msg({event:true, msg: 'Reconnect to server FAILED.'})
}
18 changes: 14 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ var http = require('http')
, latestPublicGame
, clientDir = __dirname + '/client'
, publicDir = __dirname + '/public'
, depsDir = __dirname + '/deps';
, depsDir = __dirname + '/deps'
, prod = process.env.NODE_ENV === 'production';

buildStaticFiles();

Expand Down Expand Up @@ -44,21 +45,29 @@ server = connect.createServer(
, niceifyURL
, gzip.staticGzip(publicDir, {
matchType: /text|javascript/
, maxAge: process.env.NODE_ENV === 'production' ? 86400000 : 0
, maxAge: prod ? 86400000 : 0
})
, gzip.staticGzip(publicDir + '/perm', {
matchType: /image|font/
, maxAge: process.env.NODE_ENV === 'production' ? 604800000 : 0
, maxAge: prod ? 604800000 : 0
})
);

server.listen(process.env.NODE_ENV === 'production' ? 80 : 8000);
server.listen(prod ? 80 : 8000);

io = io.listen(server);
io.configure('production', function() {
io.enable('browser client minification'); // send minified client
io.enable('browser client etag'); // apply etag caching logic based on version number
io.enable('browser client gzip'); // gzip the file
io.set('log level', 1); // reduce logging
io.set('transports', [ // enable all transports (optional if you want flashsocket)
'websocket'
, 'flashsocket'
, 'htmlfile'
, 'xhr-polling'
, 'jsonp-polling'
]);
});

function getUnusedHash() {
Expand Down Expand Up @@ -115,6 +124,7 @@ function randString(size) {

function buildStaticFiles() {
var options = {
uglifyjs: prod,
jstransport: false,
cssabspath: false,
csshost: false,
Expand Down

0 comments on commit 1e6ecef

Please sign in to comment.