-
Notifications
You must be signed in to change notification settings - Fork 227
Expand file tree
/
Copy pathapp.js
More file actions
43 lines (37 loc) · 1.09 KB
/
Copy pathapp.js
File metadata and controls
43 lines (37 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
express = require('express.io')
app = express().http().io()
redis = require('redis')
RedisStore = require('connect-redis')(express)
// Setup your sessions, just like normal.
app.use(express.cookieParser())
app.use(express.session({
secret: 'monkey',
store: new RedisStore({
client: redis.createClient()
})
}))
app.io.set('store', new express.io.RedisStore({
redisPub: redis.createClient(),
redisSub: redis.createClient(),
redisClient: redis.createClient(),
}))
// Session is automatically setup on initial request.
app.get('/', function(req, res) {
req.session.loginDate = new Date().toString()
res.sendfile(__dirname + '/client.html')
})
// Setup a route for the ready event, and add session data.
app.io.route('ready', function(req) {
req.session.name = req.data
req.session.save(function() {
req.io.emit('get-feelings')
})
})
// Send back the session data.
app.io.route('send-feelings', function(req) {
req.session.feelings = req.data
req.session.save(function() {
req.io.emit('session', req.session)
})
})
app.listen(7076)