-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
74 lines (61 loc) · 1.89 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
const express = require('express');
const cookieSession = require('cookie-session');
const passport = require('passport');
const authRoutes = require('./routes/authRoutes');
const notesRoutes = require('./routes/notesRoutes');
const profileRoutes = require('./routes/profileRoutes');
const practiseRoutes= require('./routes/practiseRoutes');
const contestRoutes = require('./routes/contestRoutes');
const followingRoutes = require('./routes/followingRoutes');
const articlesRoutes= require('./routes/articlesRoutes');
const passportSetup = require('./config/passportSetup');
const mongoose = require('mongoose');
const keys = require('./config/keys');
mongoose.promise = global.promise;
const app = express();
app.use(express.static('public'));
// set view engine
app.set('view engine', 'ejs');
// set up session cookies
app.use(cookieSession({
maxAge: 30 * 24 * 60 * 60 * 1000, // Cookie for 30 days
keys: [keys.session.cookieKey]
}));
// initialize passport
app.use(passport.initialize());
app.use(passport.session());
// connect to mongodb
mongoose.connect(keys.mongodb.dbURI,{ useNewUrlParser: true }, function(err) {
if(err)
{
throw err;
process.exit(0);
}
console.log('connected to mongodb');
});
// set up routes
app.use('/auth', authRoutes);
app.use('/profile', profileRoutes);
app.use('/notes', notesRoutes);
app.use('/contests',contestRoutes);
app.use('/practise',practiseRoutes);
app.use('/following',followingRoutes);
app.use('/articles',articlesRoutes);
app.get('/', function(req, res){
if(req.user)
{
res.redirect('/practise/');
}
else
{
res.sendFile(__dirname + '/public/html/index.html');
}
});
app.get('/error.html', function(req, res){
res.status(400);
res.sendFile(__dirname + '/public/html/error.html');
});
const port = process.env.port || 80;
app.listen(port, function(){
console.log("App listening on port " + port);
})