-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (36 loc) · 1.08 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
'use strict';
var serve = require('koa-static');
var koa = require('koa');
var bodyParser = require('koa-bodyparser');
var favicon = require('koa-favi');
var app = koa();
var Currencies = require('./currencies');
var Pair = require('./pair');
var _ = require('lodash');
app.use(favicon('/assets/'));
app.use(bodyParser());
app.use(serve(__dirname + '/public'));
app.use(function *() {
// the parsed body will store in this.request.body
// if nothing was parsed, body will be an empty object {}
this.body = this.request.body;
});
var markets = require('./markets/index');
for(let market of markets.markets) {
market.startListening();
}
// This must come after last app.use()
var server = require('http').Server(app.callback()),
io = require('socket.io')(server);
// Socket.io
io.on('connection', function(socket){
console.log('connection');
socket.emit('news', { hello: 'world' });
for(let market of markets.markets) {
market.setSocketIO(socket);
}
});
// Start the server
server.listen(3000);
console.info('Now running on localhost:3000');
// IPC