public
Last active

description of edits to enhance server.js for node-boilerplate

  • Download Gist
layout.ejs
1 2 3 4 5 6 7 8 9 10 11 12 13
<script>SOCKET_IO_PORT = <%= port %>;</script>
<script src="/js/socket.io.js"></script>
 
...
 
 
<!-- mathiasbynens.be/notes/async-analytics-snippet Change UA-XXXXX-X to be your site's ID -->
<script>
var _gaq=[["_setAccount","<%= googleAnalyticsSiteId %>"],["_trackPageview"]];
(function(d,t){var g=d.createElement(t),s=d.getElementsByTagName(t)[0];g.async=1;
g.src=("https:"==location.protocol?"//ssl":"//www")+".google-analytics.com/ga.js";
s.parentNode.insertBefore(g,s)}(document,"script"));
</script>
script.js
JavaScript
1 2 3 4 5 6 7 8 9 10
...
 
//io.setPath('/client/');
socket = new io.Socket(null, {
port: SOCKET_IO_PORT
,transports: ['websocket', 'htmlfile', 'xhr-multipart', 'xhr-polling']
,path: '/client/'
});
 
...
server.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11
// at the top of the file, or in a site config file:
var googleAnalyticsSiteId = 'UA-XXXXX-X';
 
...
 
// THREE PLACES: 404, 500, index, etc. Consider using a default "locals" object that is extended for each instance.
res.render('VARIOUS TEMPLATES', {locals: {
...
googleAnalyticsSiteId: googleAnalyticsSiteId,
port: port // only needed for the index.ejs route
}});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.