-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.js
50 lines (39 loc) · 1.37 KB
/
server.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
const express = require('express');
const app = express();
const bodyParser = require('body-parser');
if (process.env.NODE_ENV !== 'production') {
require('dotenv').load();
require('babel-register')({
ignore: /\/(build|node_modules)\//,
presets: ['env', 'react-app']
});
}
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.text());
app.use(bodyParser.json({ type: "application/vnd.api+json" }));
app.set('port', (process.env.PORT || 3001));
if (process.env.NODE_ENV === 'production') {
app.use(express.static('client/build'));
}
require('./controllers/stock-controller')(app);
const server = app.listen(app.get('port'), () => {
console.log(`Attention port ${app.get('port')}...you are go for takeoff!`);
});
const io = require('socket.io')(server);
io.on('connection', function(socket) {
console.log('component connected');
//notify all but caller of new save
socket.on('add-event', function(symbol) {
console.log('Save called', symbol);
socket.broadcast.emit('new-save', symbol);
});
//notify all but caller of delete
socket.on('remove-event', function(symbol) {
console.log('Remove called', symbol);
socket.broadcast.emit('new-delete', symbol);
});
socket.on('disconnect', function() {
console.log('component disconnected');
});
});