Skip to content

Instantly share code, notes, and snippets.

@djalmaaraujo
Created January 27, 2013 00:18
Show Gist options
  • Save djalmaaraujo/4645450 to your computer and use it in GitHub Desktop.
Save djalmaaraujo/4645450 to your computer and use it in GitHub Desktop.
// Copyright (c) 2013 Djalma Araujo
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, http = require('http')
, redis = require('redis')
, socketio = require('socket.io')
, User = require('./modules/user')
, path = require('path');
var db = redis.createClient()
, app = express()
, server = http.createServer(app);
/**
* App Config
*/
app.configure(function () {
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'ejs');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('your secret here'));
app.use(express.session());
app.use(app.router);
app.use(require('stylus').middleware(__dirname + '/public'));
app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function(){
app.use(express.errorHandler());
});
/**
* Server and Socket.IO listeners
*/
server.listen(app.get('port'), function() {
console.log("Express server listening on port " + app.get('port'));
});
var io = socketio.listen(server);
/**
* Routes
*/
app.get('/', routes.index);
/**
* Socket.IO Handler
*/
io.sockets.on('connection', function (socket) {
new User.user(socket);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment