-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (31 loc) · 909 Bytes
/
index.js
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
'use strict'
var koa = require('koa'),
router = require('koa-router'),
sockjs = require('sockjs'),
config = require('./libs/config.json'),
app = new koa(),
http = require('http'),
connections = [],
chat = sockjs.createServer(),
namespace = require('koa-router-namespace')
chat.on('connection',function(conn){
connections.push(conn);
console.log('connection:',conn);
conn.on('data', function(msg){
console.log(msg)
})
conn.on('close', function(){
console.log('Disconnected: %s', conn)
})
})
app.use(router(app))
namespace(app);
app.namespace("/" + config.app.namespace, function(){
app.get('/', function* (){
this.body = {"timestamp": Date.now()}
})
})
var server = http.createServer(app.callback()).listen(config.app.port, function(){
console.log('Listening on port: %s', config.app.port)
})
chat.installHandlers(server, {prefix: '/api/sock'})