Created
September 6, 2013 15:48
-
-
Save nadeemelahi/6465774 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var nano = require('nano'); | |
var couchdb = nano('http://127.0.0.1:5984'); | |
var redis = require('redis'); | |
var http = require('http'); | |
var connect = require('connect'); | |
var RedisStore1 = require('connect-redis')(connect); | |
var io = require('socket.io'); | |
var cookie = require('cookie'); | |
var sessionStore = new RedisStore1(); | |
var server = connect() | |
.use(connect.favicon(__dirname + '/public/img/favicon.png')) | |
.use(connect.cookieParser()) | |
.use(connect.session({ secret: 'secret-string', key: 'connect.sid', store: sessionStore, cookie: {maxAge: 604800000} })) //1week | |
.use(connect.static(__dirname + '/public'), {redirect: true}) | |
.use(function(req, res){ | |
res.end('Nothing to see here folks\n'); | |
}); | |
var httpd = http.createServer(server); | |
io = io.listen(httpd); | |
httpd.listen(8000); | |
var registeredUsersDB = couchdb.use('registered_users'); | |
var chatDB = couchdb.use('chat'); | |
var chat = io.of('/chat'); | |
RedisStore2 = require('socket.io/lib/stores/redis'), | |
pub = redis.createClient(), | |
sub = redis.createClient(), | |
client = redis.createClient(); | |
io.set('store', new RedisStore2({ | |
redisPub : pub, | |
redisSub : sub, | |
redisClient : client | |
})); | |
var userCount = 0; | |
chat.authorization(function(handshakeData, accept){ | |
handshakeData.cookie = cookie.parse(handshakeData.headers.cookie); | |
handshakeData.sessionID = connect.utils.parseSignedCookie(handshakeData.cookie['connect.sid'], 'nadeem'); | |
if (!handshakeData.sessionID) return accept('Cookie is invalid.', false) | |
accept(null, true); | |
}).on('connection', function(socket){ | |
userCount++; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment