forked from codeuino/social-platform-donut-frontend
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
93 lines (82 loc) · 2.4 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
const express = require('express');
const route = require('./routes/login.routes.js');
const google = require('./config/google.js');
const github = require('./config/github.js');
const mongoose = require('mongoose');
const passport = require('passport');
const path = require('path');
const app = express();
const cookie = require('cookie-session');
const socket = require('socket.io');
const user = require('./schema/user.js');
const secret = require('./config/credential.js');
const notification = require('./schema/notification.js');
const indexRoutes = require('./routes/index.routes');
const facebook = require('./config/facebook.js');
const memwatch = require('node-memwatch');
const expressValidator = require('express-validator');
const methodOverride = require('method-override');
//Snapshot at start
const hd = new memwatch.HeapDiff();
mongoose.connect(secret.database, function() {
console.log('connected');
});
const loged = [];
app.set('view engine', 'ejs');
app.use(express.static(path.join(__dirname, 'views')));
app.set('views',path.join(__dirname+"/views"));
app.use(methodOverride('_method'));
app.use(
cookie({
maxAge: 24 * 60 * 60 * 1000,
keys: ['CAPEDCRUSADER']
})
);
app.use(passport.initialize());
app.use(passport.session());
app.use(expressValidator());
app.use(indexRoutes);
app.get('**',(req,res)=>{
res.render('error');
});
//Snapshot after routing
const diff = hd.end();
//Diff between both snapshots
console.log(diff);
//checking for leak in memory
memwatch.on('leak', info => {
for (var x in info) {
console.log(x + ':' + info[x]);
}
});
//Stats of memory leakage
memwatch.on('stats', info => {
for (var x in info) {
console.log(x + ':' + info[x]);
}
});
const ser = app.listen(3000, function() {
console.log('Running');
});
const io = socket(ser);
io.on('connection', function(socket) {
socket.on('downvote', function(data) {
user.find().then(function(out) {
out.forEach(function(x) {
if (x['Eid'] == data.sign) {
new notification({
fname: x['fname'],
lname: x['lname'],
upvoteId: x['Eid'],
proid: data.pro['proid'],
userid: data.pro['pid']
})
.save()
.then(function(notif) {
console.log(notif);
});
}
});
});
});
});