-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
87 lines (79 loc) · 2.67 KB
/
app.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.js');
const clout = require('clout-js');
const express = require('express');
const path = require('path');
const fs = require('fs');
const NODE_ENV = process.env.NODE_ENV || 'development';
const COMPILER_WATCH_OPTIONS = {
aggregateTimeout: 300,
poll: true
};
const app = module.exports = {
compiler: null,
serverStarted: false,
onCompilerError(err) {
console.error(err);
},
onCompilerSuccess(stats) {
let durationInMS = stats.endTime - stats.startTime;
let duration = durationInMS/1000;
console.info('successfully build webpack');
console.info(`duration: ${duration}s`);
clout.registerHook('start', (next) => {
clout.app.use(express.static(this.compiler.outputPath));
clout.app.use('*', express.static(this.compiler.outputPath));
next();
}, 'CONTROLLER');
this.startServer();
},
onCompilerWatch(err, stats) {
if (err) { this.onCompilerError(err); }
this.onCompilerSuccess(stats);
},
onCompilerRun(err, stats) {
if (err) { this.onCompilerError(err); }
this.onCompilerSuccess(stats);
},
startServer() {
if (this.serverStarted) { return; }
this.serverStarted = true;
clout.on('started', function () {
if (clout.server.https) {
clout.logger.info('https server started on port %s', clout.server.https.address().port);
}
if (clout.server.http) {
clout.logger.info('http server started on port %s', clout.server.http.address().port);
}
});
clout.start();
},
initialize() {
this.compiler = webpack(webpackConfig);
switch (NODE_ENV) {
case 'production':
this.compiler.run((err, stats) => this.onCompilerRun(err, stats));
break;
default:
this.compiler.watch(COMPILER_WATCH_OPTIONS, (err, stats) => this.onCompilerWatch(err, stats));
}
},
setupSockets() {
let account = clout.exchanges.bitx;
account.getOpenOrders({pair: "LTC_USD"}, function (err, openOrders) {
if (err) {
return console.error(err);
}
console.log(openOrders);
});
clout.sio.sockets.on('connection', function (socket) {
console.log(socket.request.session.id);
socket.on('GET_CURRENCY_PRICES', () => {
socket.emit('CURRENCY_PRICES', {
hello: 'world'
});
});
});
}
};
app.initialize();