-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
102 lines (76 loc) · 2.47 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
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
const express = require('express');
const bodyParser = require('body-parser');
const path = require('path');
const cors = require('cors');
const morgan = require('morgan');
const mongoose = require('mongoose');
const routes = require('./routes');
const Pusher = require('pusher');
let cron = require('node-cron');
const api = require('./routes/api');
const pusher = new Pusher({
appId : '689385',
key : '8042ee8184c51b5ff049',
secret : '9ee8d1d20c3ceb337d83',
cluster : 'eu',
useTLS : true,
});
const channel = 'projects';
const app = express();
//PORT
const port = process.env.PORT || 8080;
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(morgan('combined'));
mongoose.connect(process.env.MONGODB_URI || "mongodb://localhost:27017/cwteam", { useNewUrlParser: true }).then(() => {
console.log("Connected to Database");
}).catch((err) => {
console.log("Not Connected to Database ERROR! ", err);
});
/*
const db = mongoose.connection;
db.on('error', console.error.bind(console, 'Connection Error:'));
db.once('open', () => {
const projectCollection = db.collection('projects');
const changeStream = projectCollection.watch();
changeStream.on('change', (change) => {
console.log(change);
if(change.operationType === 'insert') {
pusher.trigger(
channel,
'inserted',
change.fullDocument
);
} else if(change.operationType === 'delete') {
pusher.trigger(
channel,
'deleted',
change.documentKey._id
);
} else if(change.operationType === 'update') {
pusher.trigger(
channel,
'updated',{item: change.updateDescription.updatedFields, project_id: change.documentKey._id}
);
}
});
});
*/
/*const task = cron.schedule('* * * * *', () => {
console.log('triggered');
pusher.trigger(channel, 'z-report', {});
});*/
//task.start();
//routes
//app.use('/', routes);
app.use('/api', api);
app.use(express.static(path.join(__dirname, "client", "build")))
// Index route
/*app.get('*', function(req, res) {
res.sendFile(path.join(__dirname, 'client/public', 'index.html'));
});*/
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
app.listen(port, () => console.log(`Listening on port ${port}`));