-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.coffee
40 lines (27 loc) · 1.26 KB
/
app.coffee
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
handlers = require('./lib/handlers')
express = require('express')
socket = require('socket.io')
store = require('./lib/store').store
app = express.createServer()
app.use(express.logger(format: '[:date] [:response-time] [:status] [:method] [:url]'))
app.use(express.bodyParser()) # pre-parses JSON body responses
app.use(express.cookieParser()) # pre-parses JSON cookies
app.use(express.session(secret: 'BIRDY', store: store, cookie: { path: '/', httpOnly: true, maxAge: 604800 })) # keep cookie for one week
app.use(express.compiler(src: "#{__dirname}/src", dest: "#{__dirname}/public", enable: ['coffeescript'])) # looks for cs files to render as js
app.use(express.static("#{__dirname}/public"))
app.get('/connect', handlers.connect)
app.get('/callback', handlers.callback)
io = socket.listen(app)
io.configure ->
io.set('log level', 2)
io.set 'authorization', (handshakeData, callback) ->
sessionId = handshakeData.headers?.cookie?.replace(/.*connect.sid=(.+)(;|$)/, '$1')
unless sessionId
callback("invalid sessionId: #{sessionId}", false)
return
handshakeData.sessionId = decodeURIComponent(sessionId)
callback(null, true)
io.sockets.on('connection', handlers.connection)
port = 80
app.listen(port)
console.log("listening on :#{port}")