-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
57 lines (48 loc) · 1.39 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
48
49
50
51
52
53
54
55
56
57
var express = require('express');
var socket = require('socket.io');
const authRoutes = require('./routes/auth-routes');
const profileRoutes = require('./routes/profile-routes');
const passportSetup = require('./config/passport-setup');
const mongoose = require('mongoose');
const keys = require('./config/keys');
const cookieSession = require('cookie-session');
const passport = require('passport');
// App setup
var app = express();
var server = app.listen(3000, function(){
console.log('listening to port 3000');
});
// set up view engine
app.set('view engine', 'ejs');
// cookie session
app.use(cookieSession({
maxAge: 24*60*60*1000,
keys: [keys.session.cookieKey]
}));
// initialize passport
app.use(passport.initialize());
app.use(passport.session());
// connect to mongodb
mongoose.connect(keys.mongodb.dbURI, () =>{
console.log('connected to mongodb');
});
// Static files
app.use('/public', express.static('public'));
// set up routes
app.use('/auth', authRoutes);
app.use('/profile', profileRoutes);
//Socket setup
var io = socket(server);
io.on('connection', function (socket){
console.log('New user has connected', socket.id);
socket.on('chat', function(data){
io.sockets.emit('chat', data);
});
socket.on('typing', function(data){
socket.broadcast.emit('typing', data);
});
});
// create home route
app.get('/', (req, res) =>{
res.render('home', {user: req.user});
});