Skip to content

Commit

Permalink
feat(app-socket.io): build socket.io into vendor.js
Browse files Browse the repository at this point in the history
Changes:
- Move socket.io script tag inside vendor.js build
- Add `node_modules` to vendor script locations
- Change socket.io path to `/socket.io-client` in serve and client
- Will not serve socket.io.js when server is ran in `production` env
- Add `socket.io-client` to package.json for a more consistent build
  • Loading branch information
kingcody committed Aug 16, 2014
1 parent b599877 commit 06f2e46
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
3 changes: 2 additions & 1 deletion app/templates/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"passport-google-oauth": "latest",<% } %>
"composable-middleware": "^0.3.0",
"connect-mongo": "^0.4.1"<% if(filters.socketio) { %>,
"socket.io": "~1.0.6",
"socket.io": "^1.0.6",
"socket.io-client": "^1.0.6",
"socketio-jwt": "^2.0.2"<% } %>
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ angular.module '<%= scriptAppName %>'

# socket.io now auto-configures its connection when we omit a connection url
ioSocket = io '',
'reconnection limit': 10 * 1000

This comment has been minimized.

Copy link
@Climax777

Climax777 Aug 26, 2014

Why do you remove the reconnection limit?

This comment has been minimized.

Copy link
@kingcody

kingcody Aug 26, 2014

Author Member

Because in socket.io 1.x the client is now auto configured by default. Also in reading over the documentation for socket.io, socket.io-client, engine.io, and engine.io-client I saw no mention of 'reconnection limit': Number. I'm fairly sure that option no longer exists. If I am in error please let me know. Thanks.

This comment has been minimized.

Copy link
@Climax777

Climax777 Aug 27, 2014

No I completely agree. Thanks for the info.

# Send auth token on connection, you will need to DI the Auth service above
# 'query': 'token=' + Auth.getToken()
path: '/socket.io-client'

socket = socketFactory ioSocket: ioSocket

Expand Down Expand Up @@ -64,4 +64,4 @@ angular.module '<%= scriptAppName %>'
###
unsyncUpdates: (modelName) ->
socket.removeAllListeners modelName + ':save'
socket.removeAllListeners modelName + ':remove'
socket.removeAllListeners modelName + ':remove'
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ angular.module('<%= scriptAppName %>')
var ioSocket = io('', {
// Send auth token on connection, you will need to DI the Auth service above
// 'query': 'token=' + Auth.getToken()
path: '/socket.io-client'
});

var socket = socketFactory({
Expand Down Expand Up @@ -70,4 +71,4 @@ angular.module('<%= scriptAppName %>')
socket.removeAllListeners(modelName + ':remove');
}
};
});
});
4 changes: 2 additions & 2 deletions app/templates/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
<script src="bower_components/es5-shim/es5-shim.js"></script>
<script src="bower_components/json3/lib/json3.min.js"></script>
<![endif]-->
<% if(filters.socketio) { %> <script src="socket.io/socket.io.js"></script><% } %>
<!-- build:js(client) app/vendor.js -->
<!-- build:js({client<% if(filters.socketio) { %>,node_modules<% } %>}) app/vendor.js -->
<!-- bower:js -->
<!-- endbower -->
<% if(filters.socketio) { %><script src="socket.io-client/socket.io.js"></script><% } %>
<!-- endbuild -->

<!-- build:js({.tmp,client}) app/app.js -->
Expand Down
7 changes: 5 additions & 2 deletions app/templates/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ if(config.seedDB) { require('./config/seed'); }
<% } %>// Setup server
var app = express();
var server = require('http').createServer(app);<% if (filters.socketio) { %>
var socketio = require('socket.io').listen(server);
var socketio = require('socket.io')(server, {
serveClient: (config.env === 'production') ? false : true,
path: '/socket.io-client'
});
require('./config/socketio')(socketio);<% } %>
require('./config/express')(app);
require('./routes')(app);
Expand All @@ -31,4 +34,4 @@ server.listen(config.port, config.ip, function () {
});

// Expose app
exports = module.exports = app;
exports = module.exports = app;

0 comments on commit 06f2e46

Please sign in to comment.